コード例 #1
0
 function setup()
 {
     global $MODULE;
     $this->module = $MODULE;
     parent::setup();
     global $HERMES_TEST_ITEM;
     $this->test_data = $HERMES_TEST_ITEM;
     $this->query = QueryFactory::create($MODULE);
 }
コード例 #2
0
 function new_query_from_defs($criteria_defs = NULL)
 {
     global $MODULE;
     $config = $this->query_config;
     if ($criteria_defs) {
         $config['criteria_defs'] = $criteria_defs;
     }
     return QueryFactory::create($MODULE, $config);
 }
コード例 #3
0
// Get Listings class
$classname = $MODULE->listings_class;
$listings = new $classname();
// If we have an incoming command with a channel parameter, then grab it here
// as it can conflict with the normal channel QC
// NOTE AV : the use of the name channel is not ideal - I'd rename it if I was sure
// that it wouldn't break existing interfaces
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $channel_action = $_POST['channel'];
    unset($_POST['channel']);
    unset($_REQUEST['channel']);
}
// Get the current Listings Query or create a new one
$QUERY = $MODULE->get_session_data('LISTINGS_QUERY');
if (is_null($QUERY)) {
    $QUERY = QueryFactory::create($MODULE, $MODULE->listings_query_config);
}
// a way to retain what channels may have been set in the session
if (!isset($_REQUEST['channel'])) {
    $_REQUEST['channel'] = $QUERY['channel']->get_value();
}
$QUERY->set_criteria_values($_REQUEST);
$listings->process_criteria($QUERY);
// Set up global vars
$TITLE = $listings->title;
$TEMPLATE = 'listings';
$is_logged_in = $USER->has_right('save_data');
if ($is_logged_in && @count($USER->prefs['listings_channels']) == 0) {
    $USER->prefs['listings_channels'] = $QUERY['channel']->get_default();
}
// Get the output format
コード例 #4
0
// The session can be removed by passing query=new as query variable
$mode = @$_REQUEST['mode'];
// Check for table name on the URL
$table_name = NULL;
if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '' && $_SERVER['PATH_INFO'] != '/') {
    $tmp = explode('/', $_SERVER['PATH_INFO']);
    $table_name = $tmp[1];
}
// Check if it's a valid table
if ($table_name != '' && !in_array($table_name, array_keys($MODULE->list_query_tables()))) {
    header("HTTP/1.0 404 Not found");
    $MESSAGE = $STRINGS['error_404_search'];
}
// Create new query if required
if ($mode == 'new') {
    $QUERY = QueryFactory::create($MODULE, array('table_name' => $table_name));
    // set basic/advanced search based on user prefs for new searches
    if (isset($USER->prefs['search_mode'])) {
        $mode = $USER->prefs['search_mode'] == 'advanced' ? 'advanced' : 'basic';
    } else {
        // explicitly set the mode to basic
        $mode = 'basic';
    }
    $NEW_QUERY = TRUE;
    // set the new empty query in the session - this prevents old query data coming back
    QueryFactory::set_session_query($MODULE, $QUERY);
} else {
    if ($table_name != $QUERY->table_name) {
        $QUERY = QueryFactory::get_session_query($MODULE, FALSE, $table_name);
    }
}
コード例 #5
0
 static function get_session_query($module, $ignore_module_session = FALSE, $table_name = NULL, $util = NULL)
 {
     // Util for testing only
     if (is_null($util)) {
         $util = new QueryFactoryUtil($module);
     }
     if ($table_name == '') {
         $table_name = $util->get_default_table();
     }
     if ($ignore_module_session) {
         $result = @$_SESSION['QUERY'];
     } else {
         $result = $module->get_session_data('QUERY' . '/' . $table_name);
     }
     if (is_null($result)) {
         $result = QueryFactory::create($module, array('table_name' => $table_name));
     }
     return $result;
 }
コード例 #6
0
    if (is_null($ACTIVELIST)) {
        $ACTIVELIST = array();
    }
}
// User does not have permission, or saved querylist is broken
if (@$QUERYLIST == NULL) {
    $QUERYLIST = new QueryList();
    $ACTIVELIST = array();
}
// check for a form POST
if (is_array($_POST) && count($_POST) > 0 && $canSave) {
    // determine post type
    if (isset($_POST['save'])) {
        unset($_POST['save']);
        // create the query with the criteria in the post
        $query = QueryFactory::create($MODULE);
        $query->set_criteria_values($_POST);
        if (!$QUERYLIST->contains($query)) {
            if (count($QUERYLIST) >= $CONF['saved_searches_size']) {
                $MESSAGE = $STRINGS['error_saved_searches_limit'];
                $MESSAGE_CLASS = 'error-message';
            } else {
                $QUERYLIST->add($query);
                // saved searches are 'active' by default
                array_unshift($ACTIVELIST, '1');
                if (count($ACTIVELIST) > count($QUERYLIST)) {
                    array_pop($ACTIVELIST);
                }
                // save the searches
                $USER->save_data('saved_searches', $QUERYLIST);
                $USER->save_data('saved_searches_active', $ACTIVELIST);
コード例 #7
0
 function setup()
 {
     global $MODULE;
     $this->query = QueryFactory::create($MODULE);
 }
コード例 #8
0
 function after_search(&$results, $query, $criteria)
 {
     if ($query->module->name != 'fed') {
         $fed_module = Module::load('fed');
         $criteria = $query->criteria_container->get_qs_key_values();
         // Don't propagate TRILT dates, as it is annoying to get the 2 week date limit if not logged in
         if ($query->module->name == 'trilt') {
             unset($criteria['date'], $criteria['date_start'], $criteria['date_end']);
         }
         $criteria = $this->rewrite_query($criteria, $query);
         if (is_null($criteria)) {
             return;
         }
         //### FIXME: without this, queries for all records don't have 'q=' in them, this needs to be fixed in QueryCriteria class
         $criteria['page'] = 1;
         $fed_query = QueryFactory::create($fed_module);
         $url = $fed_query->url($criteria);
         $criteria_msg = '';
         if (@$criteria['q'] != '') {
             $criteria_msg = " for <b>{$criteria['q']}</b>";
         }
         $msg = "You are currently searching in <b>{$query->module->title}</b>. <a href=\"{$url}\">Search all the BUFVC's collections{$criteria_msg}</a>.";
         $query->filter_info['sidebar'][] = new SidebarBlock('Search All BUFVC', $msg);
     }
 }
コード例 #9
0
 function setup()
 {
     global $MODULE;
     $this->query = QueryFactory::create($MODULE, array('query_class' => $this->query_class_name));
 }
コード例 #10
0
 function test_menu_search_current()
 {
     $module = new DummyModule();
     $query = QueryFactory::create($module);
     $query->table_name = 'test';
     $menu = $module->menu_search($query);
     $this->assertTrue($menu['search_test']['current']);
     $this->assertFalse($menu['search_test2']['current']);
     $query->table_name = 'test2';
     $menu = $module->menu_search($query);
     $this->assertFalse($menu['search_test']['current']);
     $this->assertTrue($menu['search_test2']['current']);
 }
コード例 #11
0
 function test_criteria_string_json()
 {
     global $MODULE;
     $this->query = QueryFactory::create($MODULE);
     $expected = json_encode(array(array('name' => 'q', 'type' => 'text', 'label' => 'Search for', 'list' => array('' => 'All fields', 'title' => 'Title', 'description' => 'Description', 'person' => 'Contributors', 'keyword' => 'Keywords')), array('name' => 'text', 'type' => 'text', 'label' => 'Test'), array('name' => 'category', 'type' => 'list', 'label' => 'Genre'), array('name' => 'date', 'type' => 'drange', 'label' => 'Year', 'default' => array('1900-01-01', '1930-12-31'), 'list' => array('' => 1900, '1901' => 1901, '1902' => 1902, '1903' => 1903, '1904' => 1904, '1905' => 1905, '1906' => 1906, '1907' => 1907, '1908' => 1908, '1909' => 1909, '1910' => 1910, '1911' => 1911, '1912' => 1912, '1913' => 1913, '1914' => 1914, '1915' => 1915, '1916' => 1916, '1917' => 1917, '1918' => 1918, '1919' => 1919, '1920' => 1920, '1921' => 1921, '1922' => 1922, '1923' => 1923, '1924' => 1924, '1925' => 1925, '1926' => 1926, '1927' => 1927, '1928' => 1928, '1929' => 1929, '1930' => 1930)), array('name' => 'sort', 'type' => 'sort', 'label' => 'Sort by', 'list' => array('' => 'Date (oldest first)', 'date_desc' => 'Date (newest first)', 'title' => 'Title')), array('name' => 'page_size', 'type' => 'sort', 'label' => 'Display', 'default' => 10, 'list' => array('10' => '10', '50' => '50', '100' => '100'))));
     $this->assertEqual($expected, $this->query->criteria_string(QUERY_STRING_TYPE_JSON));
 }
コード例 #12
0
 function new_query($criteria_defs = NULL)
 {
     global $MODULE;
     $config = $this->query_config;
     if ($criteria_defs) {
         $config['criteria_defs'] = $criteria_defs;
     }
     unset($MODULE->query_config);
     //### TEMP -- to remove the query_name field
     return QueryFactory::create($MODULE, $config);
 }
コード例 #13
0
 function test_clear_search_history()
 {
     global $MODULE;
     $user = User::instance('user');
     $query = QueryFactory::create($MODULE);
     // add a query
     $user->add_to_search_history($query);
     $this->assertEqual(count($user->search_history), 1);
     $user->clear_search_history();
     // queries have been cleared
     $this->assertEqual(count($user->search_history), 0);
 }