improved the message to people who access to the serach tool without an account
cf link from daily materiO'
This commit is contained in:
parent
488d4c19aa
commit
2e1e0cc05b
@ -96,7 +96,8 @@ function materio_search_api_menu() {
|
||||
}
|
||||
|
||||
function materio_search_api_access_search(){
|
||||
return user_access('use materio search api for breves') || user_access('use materio search api');
|
||||
return true;
|
||||
// return user_access('use materio search api for breves') || user_access('use materio search api');
|
||||
}
|
||||
|
||||
|
||||
@ -355,10 +356,6 @@ function materio_search_api_term_property_dup_name($term){
|
||||
return $term->name_field[$lang][0]['value'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* - - -- - - - - - - blocks - - - - - - - - - - -
|
||||
*
|
||||
@ -766,60 +763,79 @@ function template_preprocess_materio_search_api_select_viewmode_block(&$vars){
|
||||
function template_preprocess_materio_search_api_results(array &$vars) {
|
||||
// dsm($vars, '$vars');
|
||||
$results = $vars['results'];
|
||||
$keys = $vars['keys'];
|
||||
|
||||
// $vars['items'] = $vars['index']->loadItems(array_keys($vars['results']['results']));
|
||||
$vars['result_count'] = $results['result count'];
|
||||
$vars['sec'] = round($results['performance']['complete'], 3);
|
||||
if(isset($results['result count'])){
|
||||
// $vars['items'] = $vars['index']->loadItems(array_keys($vars['results']['results']));
|
||||
$vars['result_count'] = $results['result count'];
|
||||
$vars['sec'] = round($results['performance']['complete'], 3);
|
||||
|
||||
$vars['keywords'] = implode(', ', $vars['keys']);
|
||||
$vars['keywords'] = $vars['keys'];
|
||||
|
||||
if(isset($results['breves count'])){
|
||||
if(isset($results['breves count'])){
|
||||
// for free users
|
||||
$vars['perfascard'] = true;
|
||||
$vars['search_performance'] = format_plural(
|
||||
$results['breves count'],
|
||||
'The search found 1 news ',
|
||||
'The search found @count news '
|
||||
);
|
||||
$vars['search_performance'] .= format_plural(
|
||||
$vars['result_count'] - $results['breves count'],
|
||||
'with 1 associated matter.',
|
||||
'with @count associated matters.'
|
||||
);
|
||||
$vars['search_performance'] .= format_plural(
|
||||
$results['could results']['result count'],
|
||||
' You could have found 1 result with a ',
|
||||
' You could have found <strong>@count results</strong> with a '
|
||||
);
|
||||
$vars['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187');
|
||||
|
||||
$vars['search_performance'] .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button'))));
|
||||
|
||||
}else{
|
||||
// for members
|
||||
$vars['perfascard'] = false;
|
||||
|
||||
// $vars['search_performance'] = format_plural(
|
||||
// // $results['result count'],
|
||||
// $vars['result_count'],
|
||||
// 'The search found 1 result ',
|
||||
// 'The search found @count results '
|
||||
// )
|
||||
|
||||
$vars['search_performance'] = t('The search found @count result(s) with keywords @keys.', array(
|
||||
"@count"=>$vars['result_count'],
|
||||
"@keys"=>$vars['keywords'])
|
||||
);
|
||||
|
||||
// TODO indicate how many materials and how many news
|
||||
// $vars['search_performance'] = t('The search found @count result(s) with keywords @keys. @mat materials and @new news.', array(
|
||||
// "@count"=>$vars['result_count'],
|
||||
// "@keys"=>$vars['keywords'],
|
||||
// "@mat"=>4,
|
||||
// "@new"=>7)
|
||||
// );
|
||||
}
|
||||
}else{
|
||||
//for anonymous
|
||||
$vars['perfascard'] = true;
|
||||
$vars['search_performance'] = format_plural(
|
||||
$results['breves count'],
|
||||
'The search found 1 news ',
|
||||
'The search found @count news '
|
||||
);
|
||||
$vars['search_performance'] .= format_plural(
|
||||
$vars['result_count'] - $results['breves count'],
|
||||
'with 1 associated matter.',
|
||||
'with @count associated matters.'
|
||||
);
|
||||
$vars['search_performance'] .= format_plural(
|
||||
|
||||
$perfoutput = t('Your can\'t access to the materiO\' search tool without an account.').'<br />';
|
||||
|
||||
$perfoutput .= format_plural(
|
||||
$results['could results']['result count'],
|
||||
' You could have found 1 result with a ',
|
||||
' You could have found <strong>@count results</strong> with a '
|
||||
);
|
||||
$vars['search_performance'] .= l(t('full access to materiO\'.'), 'node/11187');
|
||||
$perfoutput .= l(t('full access to materiO\'.'), 'node/11187');
|
||||
|
||||
$vars['search_performance'] .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button'))));
|
||||
|
||||
}else{
|
||||
$vars['perfascard'] = false;
|
||||
|
||||
// $vars['search_performance'] = format_plural(
|
||||
// // $results['result count'],
|
||||
// $vars['result_count'],
|
||||
// 'The search found 1 result ',
|
||||
// 'The search found @count results '
|
||||
// )
|
||||
|
||||
$vars['search_performance'] = t('The search found @count result(s) with keywords @keys.', array(
|
||||
"@count"=>$vars['result_count'],
|
||||
"@keys"=>$vars['keywords'])
|
||||
);
|
||||
|
||||
// TODO indicate how many materials and how many news
|
||||
// $vars['search_performance'] = t('The search found @count result(s) with keywords @keys. @mat materials and @new news.', array(
|
||||
// "@count"=>$vars['result_count'],
|
||||
// "@keys"=>$vars['keywords'],
|
||||
// "@mat"=>4,
|
||||
// "@new"=>7)
|
||||
// );
|
||||
$perfoutput .= l(t('Pricing'), 'node/11187', array("attributes"=>array("class"=>array('button'))));
|
||||
|
||||
$vars['search_performance'] = $perfoutput;
|
||||
}
|
||||
|
||||
|
||||
//dsm($vars, '$vars');
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,6 @@ function materio_search_api_results_search(){
|
||||
// retreive typed words separated by slahes as a sentence
|
||||
$args = func_get_args();
|
||||
$typed = implode('/', $args);
|
||||
// dsm($typed, 'typed');
|
||||
|
||||
// remove query page params
|
||||
preg_match_all('/\?page=([0-9]+)/', $typed, $pages);
|
||||
@ -135,6 +134,7 @@ function materio_search_api_results_search(){
|
||||
if($pages[0]){
|
||||
$typed = str_replace($pages[0][0], '', $typed);
|
||||
}
|
||||
// dsm($typed, 'typed');
|
||||
|
||||
global $language;
|
||||
global $user;
|
||||
@ -156,51 +156,55 @@ function materio_search_api_results_search(){
|
||||
$index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||
// dsm($index_machine_name, '$index_machine_name');
|
||||
$index = search_api_index_load($index_machine_name);
|
||||
|
||||
$could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
||||
$could_index = search_api_index_load($index_machine_name);
|
||||
}
|
||||
|
||||
// $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||
// dsm($index_machine_name, '$index_machine_name');
|
||||
$default_bundles = array();
|
||||
if(isset($index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
||||
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
||||
foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
|
||||
}
|
||||
// potential results index for anonymous and free user
|
||||
$could_index_machine_name = variable_get('mainsearchindex_'.$language->language, -1);
|
||||
$could_index = search_api_index_load($index_machine_name);
|
||||
|
||||
$bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
|
||||
// dsm($bundles_filter, 'bundles_filter');
|
||||
|
||||
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||
// dsm($viewmode, 'viewmode');
|
||||
|
||||
// if ($keys) {
|
||||
if ($typed) {
|
||||
// TODO: cache the results with cache graceful : http://drupal.org/project/cache_graceful
|
||||
try {
|
||||
|
||||
$viewmode = isset($user->data['materiosearchapi_viewmode']) ? $user->data['materiosearchapi_viewmode'] : variable_get('defaultviewmode', 'full');
|
||||
// dsm($viewmode, 'viewmode');
|
||||
|
||||
$limit = variable_get($viewmode.'_limite', '10');
|
||||
$offset = pager_find_page() * $limit; //$page*$limit;//
|
||||
|
||||
$query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
||||
// ->keys(implode(' ', $keys))
|
||||
->keys($typed)
|
||||
->range($offset, $limit);
|
||||
if(isset($index)){
|
||||
|
||||
if(count($bundles_filter)){
|
||||
$filter = $query->createFilter('OR');
|
||||
foreach ($bundles_filter as $type) {
|
||||
$filter->condition('type', $type, '=');
|
||||
// $index_machine_name = variable_get('brevessearchindex_'.$language->language, -1);
|
||||
// dsm($index_machine_name, '$index_machine_name');
|
||||
$default_bundles = array();
|
||||
if(isset($index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'])){
|
||||
$indexed_bundles = $index->options['data_alter_callbacks']['search_api_alter_bundle_filter']['settings']['bundles'];
|
||||
foreach ($indexed_bundles as $bundle) { $default_bundles[] = $bundle; }
|
||||
}
|
||||
// dsm($filter, 'filter');
|
||||
$query->filter($filter);
|
||||
|
||||
$bundles_filter = isset($user->data['materiosearchapi_bundlesfilter']) ? $user->data['materiosearchapi_bundlesfilter'] : $default_bundles;
|
||||
// dsm($bundles_filter, 'bundles_filter');
|
||||
|
||||
$query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
||||
// ->keys(implode(' ', $keys))
|
||||
->keys($typed)
|
||||
->range($offset, $limit);
|
||||
|
||||
if(count($bundles_filter)){
|
||||
$filter = $query->createFilter('OR');
|
||||
foreach ($bundles_filter as $type) {
|
||||
$filter->condition('type', $type, '=');
|
||||
}
|
||||
// dsm($filter, 'filter');
|
||||
$query->filter($filter);
|
||||
}
|
||||
|
||||
// $query->setOption('search_api_bypass_access', true);
|
||||
$query->setOption('search_api_access_account', $user);
|
||||
|
||||
$results = $query->execute();
|
||||
}
|
||||
|
||||
// $query->setOption('search_api_bypass_access', true);
|
||||
$query->setOption('search_api_access_account', $user);
|
||||
|
||||
$results = $query->execute();
|
||||
|
||||
# in case of utilisateur search, run a real search to indicate how much items you could find
|
||||
if(isset($could_index)){
|
||||
$could_query = search_api_query($could_index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))
|
||||
@ -217,58 +221,56 @@ function materio_search_api_results_search(){
|
||||
$ret['message'] = t('An error occurred while executing the search. Please try again or contact the site administrator if the problem persists.');
|
||||
watchdog('materiobasemod', 'search error: !msg.', array('!msg' => $e->getMessage()), WATCHDOG_ERROR, l(t('search page'), $_GET['q']));
|
||||
}
|
||||
|
||||
// dsm($results, 'results');
|
||||
|
||||
// $accessible_results = array();
|
||||
// foreach ($results['results'] as $nid => $entity) {
|
||||
// if(node_access('view', node_load($nid)))
|
||||
// $accessible_results[$nid] = $entity;
|
||||
// }
|
||||
// $results['results'] = $accessible_results;
|
||||
// $results['result count'] = count($accessible_results);
|
||||
if(user_access('use materio search api for breves') || user_access('use materio search api')){
|
||||
if(user_access('use materio search api')){
|
||||
$items = $index->loadItems(array_keys($results['results']));
|
||||
// dsm($items, 'items');
|
||||
// $count = $results['result count'];
|
||||
}
|
||||
else{
|
||||
$items = array();
|
||||
$breves = $index->loadItems(array_keys($results['results']));
|
||||
foreach ($breves as $nid => $breve) {
|
||||
|
||||
if(!node_access('view', $breve))
|
||||
continue;
|
||||
|
||||
|
||||
if(user_access('use materio search api')){
|
||||
$items = $index->loadItems(array_keys($results['results']));
|
||||
// dsm($items, 'items');
|
||||
// $count = $results['result count'];
|
||||
}else if(user_access('use materio search api for breves')){
|
||||
$items = array();
|
||||
$breves = $index->loadItems(array_keys($results['results']));
|
||||
foreach ($breves as $nid => $breve) {
|
||||
|
||||
if(!node_access('view', $breve))
|
||||
continue;
|
||||
|
||||
$items[] = $breve;
|
||||
$materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
||||
// dsm($materiaux, 'materiaux');
|
||||
if($materiaux){
|
||||
foreach ($materiaux as $value) {
|
||||
if(!isset($could_results['results'][$value['target_id']]))
|
||||
continue;
|
||||
$materiau = node_load($value['target_id']);
|
||||
if(node_access('view', $materiau))
|
||||
$items[] = $materiau;
|
||||
$items[] = $breve;
|
||||
$materiaux = field_get_items('node',$breve,'field_materiau_ref');
|
||||
// dsm($materiaux, 'materiaux');
|
||||
if($materiaux){
|
||||
foreach ($materiaux as $value) {
|
||||
if(!isset($could_results['results'][$value['target_id']]))
|
||||
continue;
|
||||
$materiau = node_load($value['target_id']);
|
||||
if(node_access('view', $materiau))
|
||||
$items[] = $materiau;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results['breves count'] = $results['result count'];
|
||||
$results['result count'] = count($items);
|
||||
$results['could results'] = $could_results;
|
||||
}
|
||||
|
||||
$results['breves count'] = $results['result count'];
|
||||
$results['result count'] = count($items);
|
||||
$ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
||||
$ret['results']['#items'] = $items;
|
||||
}
|
||||
else{
|
||||
// for anonymous
|
||||
$results['could results'] = $could_results;
|
||||
}
|
||||
|
||||
|
||||
$ret['results']['#theme'] = 'materio_search_api_results';
|
||||
$ret['results']['#index'] = $index;//search_api_index_load($index_machine_name);
|
||||
// dsm($typed, 'typed');
|
||||
// for all case
|
||||
$ret['results']['#results'] = $results;
|
||||
$ret['results']['#items'] = $items;
|
||||
$ret['results']['#view_mode'] = $viewmode;
|
||||
// $ret['results']['#keys'] = $keys;
|
||||
$ret['results']['#theme'] = 'materio_search_api_results';
|
||||
$ret['results']['#keys'] = $typed;
|
||||
$ret['results']['#view_mode'] = $viewmode;
|
||||
|
||||
|
||||
drupal_set_title('<i class="icon-materio-search"></i>'.check_plain($typed), PASS_THROUGH);
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
<?php //if (!empty($result_count)) : ?>
|
||||
<div class="materiobase-results <?php print ' view-mode-' . $variables['view_mode'];?>">
|
||||
<?php if ($result_count) : ?>
|
||||
<?php //if ($result_count) : ?>
|
||||
<?php if(!$perfascard): ?>
|
||||
<p class="search-performance"><?php print render($search_performance); ?></P>
|
||||
<?php endif; ?>
|
||||
@ -55,11 +55,13 @@
|
||||
<?php
|
||||
// TODO: use cache system to gain in speed, view http://drupal.org/node/930760
|
||||
?>
|
||||
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
|
||||
<?php if ($result_count) : ?>
|
||||
<?php print render(entity_view($index->item_type, $items, $variables['view_mode'])); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php print $pager; ?>
|
||||
<?php else : ?>
|
||||
<p class="search-noresults"><?php print t('Your search yielded no results.');?></p>
|
||||
<?php endif; ?>
|
||||
<?php //else : ?>
|
||||
<!-- <p class="search-noresults"><?php print t('Your search yielded no results.');?></p> -->
|
||||
<?php //endif; ?>
|
||||
</div>
|
||||
<?php //endif; ?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user