actuality
Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
parent
2248bfd12e
commit
f8af96a85b
@ -70,9 +70,17 @@ function materio_search_api_menu() {
|
||||
$items['explore'] = $base+array(
|
||||
'access arguments' => array('use materio search api'),
|
||||
'page callback' => 'materio_search_api_results_search',
|
||||
'title' => t('Explore'),
|
||||
//'page argument' => array(1,2,3),
|
||||
);
|
||||
|
||||
$items['actuality'] = $base+array(
|
||||
// 'access arguments' => array(),
|
||||
'page callback' => 'materio_search_api_actuality',
|
||||
// 'page argument' => array(),
|
||||
'access callback' => TRUE,
|
||||
);
|
||||
|
||||
$items['materiosearchapi/viewmode/change'] = $base+array(
|
||||
'access arguments' => array('use materio search api'),
|
||||
'page callback' => 'materio_search_api_viewmode_change',
|
||||
@ -306,9 +314,33 @@ function materio_search_api_theme($existing, $type, $theme, $path) {
|
||||
'pager' => NULL,
|
||||
),
|
||||
),
|
||||
// 'materio_search_api_performance' => array(
|
||||
// 'render element' => 'element',
|
||||
// ),
|
||||
'materio_search_api_actuality' => array(
|
||||
'template' => 'materio-search-api-actuality',
|
||||
'path' => drupal_get_path('module', 'materio_search_api').'/templates',
|
||||
'arguments' => array(
|
||||
'items' => array(),
|
||||
'view_mode' => "teaser",
|
||||
'pager' => NULL,
|
||||
'count' => 0,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements theme for rendering search-performance
|
||||
*/
|
||||
// function theme_materio_search_api_performance($variables) {
|
||||
// $element = array_shift($variables);
|
||||
|
||||
// return $element['#markup'];
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* template_preprocess_materiobase_search_block();
|
||||
*/
|
||||
@ -389,17 +421,12 @@ function template_preprocess_materio_search_api_results(array &$variables) {
|
||||
$variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
|
||||
$variables['result_count'] = $results['result count'];
|
||||
$variables['sec'] = round($results['performance']['complete'], 3);
|
||||
$variables['search_performance'] = array(
|
||||
'#theme' => 'search_performance',
|
||||
'#markup' => format_plural(
|
||||
$variables['search_performance'] = format_plural(
|
||||
$results['result count'],
|
||||
'The search found 1 result in @sec seconds.',
|
||||
'The search found @count results in @sec seconds.',
|
||||
'The search found 1 result.', // in @sec seconds
|
||||
'The search found @count results.', // in @sec seconds
|
||||
array('@sec' => $variables['sec'])
|
||||
),
|
||||
'#prefix' => '<p class="search-performance">',
|
||||
'#suffix' => '</p>',
|
||||
);
|
||||
);
|
||||
|
||||
// $variables['search_results'] = array(
|
||||
// '#theme' => 'search_results_list',
|
||||
@ -409,10 +436,21 @@ function template_preprocess_materio_search_api_results(array &$variables) {
|
||||
// 'type' => 'ul',
|
||||
// );
|
||||
|
||||
// dsm($variables, 'variables');
|
||||
//dsm($variables, 'variables');
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_materio_search_api_actuality(&$vars){
|
||||
// dsm($vars, 'template_preprocess_materio_search_api_actuality | vars');
|
||||
|
||||
// $items = array();
|
||||
// foreach ($vars['items'] as $nid => $item) {
|
||||
// $items[] = node_load($nid);
|
||||
// }
|
||||
// $vars['items'] = $items;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* - - - - - - - - - - - - SEARCH API PAGE - - - - - - - - - - - -
|
||||
*/
|
||||
|
@ -242,27 +242,66 @@ function materio_search_api_results_search(){//, $limit = 20, $page = 0
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* materio_search_api_actuality()
|
||||
*
|
||||
*/
|
||||
function materio_search_api_actuality(){
|
||||
|
||||
$date = strtotime('-6 month');
|
||||
|
||||
$limit = 10;//variable_get($viewmode.'_limite', '10');
|
||||
$offset = pager_find_page() * $limit;
|
||||
|
||||
$query = new EntityFieldQuery;
|
||||
$query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->propertyCondition('status', 1)
|
||||
->entityCondition('bundle', array('breve'))
|
||||
->propertyCondition('created', $date, '>')
|
||||
->propertyOrderBy('created', 'DESC')
|
||||
->range($offset,$limit);
|
||||
|
||||
$result = $query->execute();
|
||||
// dsm($result, '$result');
|
||||
|
||||
$count_query = new EntityFieldQuery;
|
||||
$count = $count_query
|
||||
->entityCondition('entity_type', 'node')
|
||||
->propertyCondition('status', 1)
|
||||
->entityCondition('bundle', array('breve'))
|
||||
->propertyCondition('created', $date, '>')
|
||||
->count()->execute();
|
||||
// dsm($count, 'count');
|
||||
|
||||
pager_default_initialize($count, $limit);
|
||||
|
||||
|
||||
function materio_search_api_viewmode_change($vm){
|
||||
// dsm($vm);
|
||||
foreach ($result['node'] as $nid => $n) {
|
||||
$breve = node_load($nid);
|
||||
|
||||
if(!node_access('view', $breve))
|
||||
continue;
|
||||
|
||||
global $user;
|
||||
// dsm($user, 'user');
|
||||
|
||||
$entity_infos = entity_get_info();
|
||||
// dsm($entity_infos, 'entity_infos');
|
||||
|
||||
if (in_array($vm, variable_get('availableviewmodes', array()))) {
|
||||
user_save($user, array("data"=>array('materiosearchapi_viewmode' => $vm)));
|
||||
$rep = array('statut'=>'saved');
|
||||
}else{
|
||||
$rep = array('statut'=>'viewmode not allowed');
|
||||
$items[] = $breve;
|
||||
$materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
||||
// dsm($materiaux, 'materiaux');
|
||||
if($materiaux){
|
||||
foreach ($materiaux as $value) {
|
||||
$materiau = node_load($value['target_id']);
|
||||
if(node_access('view', $materiau))
|
||||
$items[] = $materiau;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return 'debug mode for materio_search_api_viewmode_change';
|
||||
drupal_json_output($rep);
|
||||
|
||||
|
||||
return theme('materio_search_api_actuality', array(
|
||||
'items' => $items,
|
||||
'view_mode' => 'cardmedium',
|
||||
'count' => $count,
|
||||
'pager' => theme('pager'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -52,6 +52,14 @@ function materio_search_api_ajax_menu() {
|
||||
'page callback' => 'materio_search_api_ajax_viewmode_change',
|
||||
'page argument' => array(3),
|
||||
);
|
||||
|
||||
$items['materio_search_api_ajax/actuality'] = array(
|
||||
'type' => MENU_CALLBACK,
|
||||
'file' => 'materio_search_api_ajax.pages.inc',
|
||||
'page callback' => 'materio_search_api_ajax_actuality',
|
||||
'access callback' => TRUE,
|
||||
'page arguments' => array(2),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
@ -107,4 +107,51 @@ function materio_search_api_ajax_viewmode_change($vm){
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
|
||||
|
||||
function materio_search_api_ajax_actuality($page = 0){
|
||||
$_GET['page'] = $page;
|
||||
|
||||
$path = 'actuality';
|
||||
|
||||
// check if request is ajax, if not rediret to search_api_page page with right keys
|
||||
if (!$debug && (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest')) {
|
||||
drupal_goto($path, array(), 301);
|
||||
exit ;
|
||||
}
|
||||
|
||||
// get results
|
||||
menu_set_active_item($path);
|
||||
$return = menu_execute_active_handler($path, FALSE);
|
||||
|
||||
//dsm($return, '$return');
|
||||
|
||||
if (is_int($return)) {
|
||||
switch ($return) {
|
||||
case MENU_NOT_FOUND :
|
||||
drupal_add_http_header('Status', '404 Not Found');
|
||||
break;
|
||||
case MENU_ACCESS_DENIED :
|
||||
drupal_add_http_header('Status', '403 Forbidden');
|
||||
break;
|
||||
case MENU_SITE_OFFLINE :
|
||||
drupal_add_http_header('Status', '503 Service unavailable');
|
||||
break;
|
||||
}
|
||||
} elseif (isset($return)) {
|
||||
|
||||
if (is_array($return)) {
|
||||
$return = drupal_render($return);
|
||||
}
|
||||
|
||||
$rep = array(
|
||||
'return'=>$return,
|
||||
);
|
||||
|
||||
if ($debug) {
|
||||
dsm($rep, 'rep');
|
||||
return "debug display";
|
||||
}else{
|
||||
drupal_json_output($rep);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user