Changeset 11871

Show
Ignore:
Timestamp:
08/30/07 15:35:49 (1 year ago)
Author:
adrenalin
Message:

Changed sorting to use midgard_collector instead of query builder

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/org.routamc.gallery/config/manifest.inc

    r11649 r11871  
    11'name' => 'org.routamc.gallery', 
    22'purecode' => false, 
    3 'version' => '1.1.0beta3', 
     3'version' => '1.1.0beta2', 
    44'state' => 'beta', 
    55'privileges' => array (), 
  • trunk/midcom/org.routamc.gallery/config/schemadb_config.inc

    r11646 r11871  
    2828            ), 
    2929            'widget' => 'select', 
     30            'start_fieldgroup' => array 
     31            ( 
     32                'title' => 'groovy', 
     33            ), 
    3034        ), 
    3135        'handpicked_photos' => array 
     
    6367                ), 
    6468            ), 
     69            'end_fieldgroup' => '', 
    6570        ), 
    6671        'photos_per_page' => array 
  • trunk/midcom/org.routamc.gallery/navigation.php

    r5989 r11871  
    6161        foreach ($organizer->get_sorted() as $link_id => $photo) 
    6262        { 
    63             if (version_compare(mgd_version(), '1.8.0', '>=')) 
    64             { 
    65                 $creator = $photo->metadata->creator; 
    66                 $revisor = $photo->metadata->revisor; 
    67                 $created = $photo->metadata->created; 
    68                 $revised = $photo->metadata->revised; 
    69             } 
    70             else 
    71             { 
    72                 $creator = $photo->creator; 
    73                 $revisor = $photo->revisor; 
    74                 $created = $photo->created; 
    75                 $revised = $photo->revised; 
    76             } 
    77              
    7863            $leaves[$link_id] = array 
    7964            ( 
    80                 MIDCOM_NAV_SITE => Array 
    81                 ( 
    82                     MIDCOM_NAV_URL => "photo/{$photo->guid}.html", 
    83                     MIDCOM_NAV_NAME => $photo->title 
    84                 ), 
     65                MIDCOM_NAV_URL => "photo/{$photo->guid}.html", 
     66                MIDCOM_NAV_NAME => $photo->title, 
    8567                MIDCOM_NAV_ADMIN => null, 
    8668                MIDCOM_NAV_GUID => $photo->guid, 
    8769                MIDCOM_NAV_OBJECT => $photo, 
    88                 MIDCOM_META_CREATOR => $creator, 
    89                 MIDCOM_META_EDITOR => $revisor, 
    90                 MIDCOM_META_CREATED => $created, 
    91                 MIDCOM_META_EDITED => $revised, 
    9270            ); 
    9371 
  • trunk/midcom/org.routamc.gallery/organizer.php

    r11646 r11871  
    3232     
    3333    /** 
    34      * Should post processing be done to photo links (pre Midgard 1.8.2) 
    35      *  
    36      * @access private 
    37      */ 
    38     var $_post_processing = true; 
    39      
    40     /** 
    41      * Should legacy support be enabled (i.e. pre Midgard 1.8.2) 
    42      *  
    43      * @access private 
    44      * @var boolean $_legacy 
    45      */ 
    46     var $_legacy = true; 
    47      
    48     /** 
    4934     * Limit the request to a certain number 
    5035     *  
     
    7762    function org_routamc_gallery_organizer($sort_string = null) 
    7863    { 
    79         if (version_compare(mgd_version(), '1.8.2', '>=')) 
    80         { 
    81             $this->_legacy = false; 
    82             $this->_post_processing = false; 
    83         } 
    84          
    8564        if ($sort_string) 
    8665        { 
     
    10685    function sort_by($string) 
    10786    { 
    108         debug_push_class(__CLASS__, __FUNCTION__); 
    109          
    11087        if (trim($string) === '') 
    11188        { 
    112             debug_add('No sorting string set, using default'); 
    113             debug_pop(); 
    114              
    11589            return true; 
    11690        } 
     
    136110            $domain = $regs[0]; 
    137111            $string = $regs[1]; 
    138             $post_processing = true; 
    139112        } 
    140113         
     
    142115        { 
    143116            case 'score': 
    144                 if ($this->_legacy) 
    145                 { 
    146                     $sort = 'score'; 
    147                     $post_processing = false; 
    148                 } 
    149                 else 
    150                 { 
    151                     $sort = 'metadata.score'; 
    152                 } 
     117                $sort = 'metadata.score'; 
    153118                 
    154119                break; 
    155120             
    156121            default: 
    157                 if ($this->_legacy) 
    158                 { 
    159                     $sort = $string; 
    160                 } 
    161                 else 
    162                 { 
    163                     $sort = strtolower("{$domain}{$string}"); 
    164                 } 
     122                $sort = strtolower("{$domain}{$string}"); 
    165123        } 
    166124         
    167125        $this->sort = $sort; 
    168126         
    169         debug_add("Sorting will be done according to property '{$this->sort}'"); 
    170          
    171         if (isset($post_processing)) 
    172         { 
    173             debug_add('Pre Midgard 1.8.2 post processing is required'); 
    174             $this->_post_processing = $post_processing; 
    175         } 
    176          
    177         debug_pop(); 
    178127        return true; 
    179128    } 
     
    188137    { 
    189138        // Initialize the query builder 
    190         $qb = org_routamc_gallery_photolink_dba::new_query_builder(); 
    191         $qb->add_constraint('node', '=', $this->node); 
     139        $mc = org_routamc_gallery_photolink_dba::new_collector('node', $this->node); 
     140        $mc->add_value_property('id'); 
     141        $mc->add_value_property('node'); 
     142        $mc->add_value_property('photo'); 
     143         
     144        $mc->add_constraint('censored', '=', 0); 
     145        $mc->add_order($this->sort); 
    192146         
    193147        // Set the offset 
    194148        $offset = $this->limit * $this->page; 
    195149         
    196         // Shorten the variable name 
    197         $sort = $this->sort; 
     150        // Set limit 
     151        if ($this->limit) 
     152        { 
     153            $mc->set_limit($this->limit); 
     154        } 
     155         
     156        // Add offset 
     157        if ($this->page) 
     158        { 
     159            $mc->add_offset($offset); 
     160        } 
     161         
     162        // Execute the collector 
     163        $mc->execute(); 
     164         
     165        $links = $mc->list_keys(); 
    198166         
    199167        // Initialize results set 
    200168        $results = array (); 
    201169         
    202         // No post processing required, get the results straight 
    203         if (!$this->_post_processing) 
     170        foreach ($links as $guid => $array) 
    204171        { 
    205             $qb->add_order($this->sort); 
    206              
    207             // Set limit 
    208             if ($this->limit) 
    209             { 
    210                 $qb->set_limit($this->limit); 
    211             } 
    212              
    213             // Add offset 
    214             if ($this->page) 
    215             { 
    216                 $qb->add_offset($offset); 
    217             } 
    218              
    219             // Get the results 
    220             $results = array(); 
    221              
    222             foreach ($qb->execute() as $link) 
    223             { 
    224                 $photo[$link->id] = new org_routamc_photostream_photo_dba($link->photo); 
    225                  
    226                 if (@$photo->censored) 
    227                 { 
    228                     continue; 
    229                 } 
    230                  
    231                 $results[$link->id] =& $photo[$link->id]; 
    232             } 
    233              
    234             // Return reversed results 
    235             if ($this->reverse) 
    236             { 
    237                 return array_reverse($results, true); 
    238             } 
    239              
    240             return $results; 
     172            $results[$mc->get_subkey($guid, 'id')] = new org_routamc_photostream_photo_dba($mc->get_subkey($guid, 'photo')); 
    241173        } 
    242         else 
     174         
     175        // Return reversed results 
     176        if ($this->reverse) 
    243177        { 
    244             $links = array (); 
    245             $photos = array (); 
    246              
    247             foreach ($qb->execute() as $link) 
    248             { 
    249                 $photo = new org_routamc_photostream_photo_dba($link->photo); 
    250                  
    251                 if (@$photo->censored) 
    252                 { 
    253                     continue; 
    254                 } 
    255                  
    256                 // QUICKFIX: the sort is specified in QB format, but of course it's not a valid property name 
    257                 if (strpos($sort, '.') !== false) 
    258                 { 
    259                     list ($prop1, $prop2) = explode('.', $sort, 2); 
    260                     $links[$link->id] = $photo->$prop1->$prop2; 
    261                 } 
    262                 else 
    263                 {                 
    264                     $links[$link->id] = $photo->$sort; 
    265                 } 
    266                 $photos[$link->id] = $photo; 
    267             } 
    268              
    269             // Sort the links 
    270             if ($this->reverse) 
    271             { 
    272                 arsort($links); 
    273             } 
    274             else 
    275             { 
    276                 asort($links); 
    277             } 
    278              
    279             // Set limit 
    280             if ($this->limit) 
    281             { 
    282                 $limit = $this->limit; 
    283             } 
    284             else 
    285             { 
    286                 $limit = count($links); 
    287             } 
    288              
    289             $i = 0; 
    290              
    291             foreach ($links as $link_id => $value) 
    292             { 
    293                 // Skip due to paging 
    294                 if ($i < $offset) 
    295                 { 
    296                     continue; 
    297                 } 
    298                  
    299                 // Break due to paging 
    300                 if ($i > $offset + $limit) 
    301                 { 
    302                     break; 
    303                 } 
    304                  
    305                 $results[$link_id] =& $photos[$link_id]; 
    306             } 
     178            return array_reverse($results, true); 
    307179        } 
    308180