Changeset 26353


Ignore:
Timestamp:
06/13/10 13:39:45 (7 years ago)
Author:
rambo
Message:

search interface with quick-create buttons

Location:
branches/ragnaroek/midcom/net.hurttakallio.library
Files:
8 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/ragnaroek/midcom/net.hurttakallio.library/config/config.inc

    r26343 r26353  
    44'schemadb_entities' => 'file:/net/hurttakallio/library/config/schemadb_entities_default.inc',
    55'schemadb_config' => 'file:/net/hurttakallio/library/config/config_schemadb.inc',
     6// Properties that can be used instantiate an item via URL /item/xxx -urls
     7'item_instantiation_properties' => array
     8(
     9    'guid',
     10    'barcode',
     11    'asin',
     12    'isxn',
     13),
     14// In addition to the instantiation_properties above, search from these fields when using quicksearch
     15'item_search_properties' => array
     16(
     17    'title',
     18    /**
     19     * If you actually use ddc I suggest adding it here
     20    'ddc',
     21     */
     22),
  • branches/ragnaroek/midcom/net.hurttakallio.library/handler/index.php

    r26341 r26353  
    4545    function _handler_index($handler_id, $args, &$data)
    4646    {
    47         $this->_request_data['name']  = "net.hurttakallio.library";
    48         // the handler must return true
    49         /***
    50          * Set the breadcrumb text
    51          */
    52         $this->_update_breadcrumb_line($handler_id);
    53         /**
    54          * change the pagetitle. (must be supported in the style)
    55          */
    56         $title = $this->_l10n_midcom->get('index');
    57         $_MIDCOM->set_pagetitle(":: {$title}");
    58         /**
    59          * Example of getting a config var.
    60          */
    61         $this->_request_data['sort_order'] = $this->_config->get('sort_order');
    6247        return true;
    6348    }
     
    7156    function _show_index($handler_id, &$data)
    7257    {
    73         // hint: look in the style/index.php file to see what happens here.
    74         midcom_show_style('index');
    75     }
    76 
    77     /**
    78      * Helper, updates the context so that we get a complete breadcrumb line towards the current
    79      * location.
    80      *
    81      */
    82     function _update_breadcrumb_line()
    83     {
    84         $tmp = Array();
    85 
    86         $tmp[] = Array
    87         (
    88             MIDCOM_NAV_URL => "/",
    89             MIDCOM_NAV_NAME => $this->_l10n->get('index'),
    90         );
    91 
    92         $_MIDCOM->set_custom_context_data('midcom.helper.nav.breadcrumb', $tmp);
     58        midcom_show_style('nhl-show-index');
    9359    }
    9460}
  • branches/ragnaroek/midcom/net.hurttakallio.library/handler/item.php

    r26350 r26353  
    1717
    1818    /**
    19      * Used for deciding which properties to use when querying object and determining the url
     19     * Used for deciding which properties to use when querying object and determining the url, note: overridden from config
    2020     */
    21     var $query_properties = array
     21    var $instantiation_properties = array
    2222    (
    2323        'guid',
    24         'barcode',
    25         'asin',
    26         'isxn',
    2724    );
     25   
     26    /**
     27     * Properties to search when using the quicksearch mode (filled in construct)
     28     */
     29    var $search_properties = array();
    2830
    2931    public function __construct()
     
    3234        $this->_prefix = 'nhl_item';
    3335        parent::__construct();
     36    }
     37
     38    public function _resolve_search_properties()
     39    {
     40        $this->instantiation_properties = $this->_config->get('item_instantiation_properties');
     41        $this->search_properties = array_merge
     42        (
     43            $this->instantiation_properties,
     44            $this->_config->get('item_search_properties')
     45        );
    3446    }
    3547
     
    105117    public function _get_object_url()
    106118    {
    107         foreach ($this->query_properties as $property)
     119        foreach ($this->instantiation_properties as $property)
    108120        {
    109121            if ($property === 'guid')
     
    158170    public function _load_object($handler_id, $args, &$data)
    159171    {
     172        $this->_resolve_search_properties();
    160173        $qb = net_hurttakallio_library_item_dba::new_query_builder();
    161174        $qb->begin_group('OR');
    162         foreach ($this->query_properties as $property)
     175        foreach ($this->instantiation_properties as $property)
    163176        {
    164177            $qb->add_constraint($property, '=', $args[0]);
     
    177190            // many results (should not happen but could in case of GIGO), check properties in order for first match
    178191            $keys = array_keys($results);
    179             foreach ($this->query_properties as $property)
     192            foreach ($this->instantiation_properties as $property)
    180193            {
    181194                foreach ($keys as $key)
     
    206219        return;
    207220    }
     221
     222    public function _handler_quicksearch($handler_id, $args, &$data)
     223    {
     224        $this->_resolve_search_properties();
     225        $this->_mode = 'read';
     226
     227        $data['questions_str'] = '';
     228        if (   isset($_GET['q'])
     229            && !empty($_GET['q']))
     230        {
     231            if (!is_array($_GET['q']))
     232            {
     233                $data['questions'] = preg_split("/\s+/", $_GET['q']);
     234            }
     235            else
     236            {
     237                $data['questions'] = $_GET['q'];
     238            }
     239            $data['questions_str'] = implode(' ', $data['questions']);
     240            // PONDER: Use qbpager instead ? (some queries might return a lot of results...)
     241            $qb = net_hurttakallio_library_item_dba::new_query_builder();
     242            $qb->begin_group('OR');
     243            foreach ($this->search_properties as $property)
     244            {
     245                foreach ($data['questions'] as $q)
     246                {
     247                    // Convert traditional wildcards to SQL ones
     248                    $q = str_replace('*', '%', $q);
     249                    // Wrap terms in wildcards if none present
     250                    if (strpos($q, '%') === false)
     251                    {
     252                        $q = "%{$q}%";
     253                    }
     254                    $qb->add_constraint($property, 'LIKE', $q);
     255                }
     256                unset($q);
     257            }
     258            unset($property);
     259            $qb->end_group();
     260            $data['items'] = $qb->execute();
     261            $data['qb'] =& $qb;
     262            // Single result, redirect
     263            if (count($data['items']) === 1)
     264            {
     265                $this->_object =& $data['items'][0];
     266                $_MIDCOM->relocate($this->_get_object_url());
     267                // This will exit()
     268            }
     269            $this->_load_schemadb();
     270            // Do not use _load_datamanager since it supposes we already have object
     271            $this->_datamanager = new midcom_helper_datamanager2_datamanager($this->_schemadb);
     272            if (!$this->_datamanager)
     273            {
     274                $_MIDCOM->generate_error(MIDCOM_ERRCRIT, 'Failed to initialize DM2');
     275                // This will exit()
     276            }
     277            $this->_prepare_request_data();
     278        }
     279
     280        $this->_handler_callback($handler_id, $args, $data);
     281        return true;
     282    }
     283
     284    public function _show_quicksearch($handler_id, &$data)
     285    {
     286        if (isset($data['items']))
     287        {
     288            if (empty($data['items']))
     289            {
     290                midcom_show_style('nhl-quicksearch-no_items');
     291                return;
     292            }
     293            midcom_show_style('nhl-quicksearch-item_results_header');
     294            $data['prefix'] = $_MIDCOM->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX);
     295            foreach (array_keys($data['items']) as $k)
     296            {
     297                $this->_object =& $data['items'][$k];
     298                $data['object'] =& $this->_object;
     299                $data['item_url'] = $data['prefix'] . $this->_get_object_url();
     300                if (!$this->_datamanager->autoset_storage($this->_object))
     301                {
     302                    debug_push_class(__CLASS__, __FUNCTION__);
     303                    debug_add("Failed to autoset_storage() for object {$this->_object->guid}", MIDCOM_LOG_ERROR);
     304                    debug_pop();
     305                    continue;
     306                }
     307                midcom_show_style('nhl-quicksearch-item_results_row');
     308            }
     309            midcom_show_style('nhl-quicksearch-item_results_footer');
     310            return;
     311        }
     312        midcom_show_style('nhl-quicksearch-item_search_header');
     313        midcom_show_style('nhl-quicksearch-item_search_form');
     314        midcom_show_style('nhl-quicksearch-item_search_footer');
     315    }
     316
     317
    208318}
    209319?>
  • branches/ragnaroek/midcom/net.hurttakallio.library/style/nhl-show-index.php

    r26348 r26353  
    1 <h1><?php echo $data['l10n']->get('This is the index'); ?></h1>
    2 <p>
    3     <?php echo $data['l10n']->get('You can change this to something else :-)'); ?>
    4    
    5 </p>
    6 <p>Sortorder: &(data['sort_order']);</p>
     1<?php
     2// Don't bother with proper index yet, just DL the quicksearch form
     3$_MIDCOM->dynamic_load($_MIDCOM->get_context_data(MIDCOM_CONTEXT_ANCHORPREFIX) . 'item/quicksearch/');
     4?>
  • branches/ragnaroek/midcom/net.hurttakallio.library/viewer.php

    r26348 r26353  
    4848        foreach(array('item', 'entity') as $type)
    4949        {
     50            // Handle /{$type}/quicksearch
     51            $this->_request_switch["quicksearch-{$type}"] = array
     52            (
     53                'handler' => array("net_hurttakallio_library_handler_{$type}", 'quicksearch'),
     54                'fixed_args' => array($type, 'quicksearch'),
     55            );
     56
     57            // Handle /{$type}/quicksearch/raw
     58            $this->_request_switch["raw-quicksearch-{$type}"] = array
     59            (
     60                'handler' => array("net_hurttakallio_library_handler_{$type}", 'quicksearch'),
     61                'fixed_args' => array($type, 'quicksearch', 'raw'),
     62            );
     63
    5064            // Handle /{$type}/xxx
    5165            $this->_request_switch["view-{$type}"] = array
     
    111125                'variable_args' => 1,
    112126            );
     127
    113128        }
    114129
Note: See TracChangeset for help on using the changeset viewer.