Changeset 3003a0c0d5bbc65f6c4134bf7f96d20eaaa65339

Show
Ignore:
Timestamp:
10/08/11 11:56:05 (8 months ago)
Author:
Xemle <xemle@phtagr.org>
Children:
3ee918f972a91be207cf67e3793a87a5cce5e711
Parents:
5511ea68dc1694dc8f00a8a4e8fb8b2973bdf048
git-author:
Xemle <xemle@phtagr.org> / 2011-10-08T11:48:14Z+0200
git-committer:
Xemle <xemle@phtagr.org> / 2011-10-08T11:56:05Z+0200
Message:

Improve negated autocomplete of explorer

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • controllers/explorer_controller.php

    r5511ea6 r3003a0c  
    220220  function _getAssociation($type, $value) { 
    221221    $result = array(); 
     222    $isNegated = false; 
     223    $normalized = $value; 
     224    if ($value && $value[0] = '-') { 
     225      $normalized = trim(substr($value, 1)); 
     226      $isNegated = true; 
     227    } 
     228    if (!$normalized) { 
     229      return $result; 
     230    } 
    222231    switch ($type) { 
    223232      case 'tag': 
    224233        $data = $this->Media->Tag->find('all', array( 
    225           'conditions' => array('name LIKE' => $value.'%'),  
     234          'conditions' => array('name LIKE' => $normalized.'%'),  
    226235          'limit' => 10 
    227236          )); 
     
    230239      case 'category': 
    231240        $data = $this->Media->Category->find('all', array( 
    232           'conditions' => array('name LIKE' => $value.'%'), 
     241          'conditions' => array('name LIKE' => $normalized.'%'), 
    233242          'limit' => 10 
    234243          )); 
     
    237246      case 'location': 
    238247        $data = $this->Media->Location->find('all', array( 
    239           'conditions' => array('name LIKE' => $value.'%'), 
     248          'conditions' => array('name LIKE' => $normalized.'%'), 
    240249          'limit' => 10 
    241250          )); 
     
    244253      case 'city': 
    245254        $data = $this->Media->Location->find('all', array( 
    246           'conditions' => array('name LIKE' => $value.'%', 'type' => LOCATION_CITY), 
     255          'conditions' => array('name LIKE' => $normalized.'%', 'type' => LOCATION_CITY), 
    247256          'limit' => 10 
    248257          )); 
     
    251260      case 'sublocation': 
    252261        $data = $this->Media->Location->find('all', array( 
    253           'conditions' => array('name LIKE' => $value.'%', 'type' => LOCATION_SUBLOCATION), 
     262          'conditions' => array('name LIKE' => $normalized.'%', 'type' => LOCATION_SUBLOCATION), 
    254263          'limit' => 10 
    255264          )); 
     
    258267      case 'state': 
    259268        $data = $this->Media->Location->find('all', array( 
    260           'conditions' => array('name LIKE' => $value.'%', 'type' => LOCATION_STATE), 
     269          'conditions' => array('name LIKE' => $normalized.'%', 'type' => LOCATION_STATE), 
    261270          'limit' => 10 
    262271          )); 
     
    265274      case 'country': 
    266275        $data = $this->Media->Location->find('all', array( 
    267           'conditions' => array('name LIKE' => $value.'%', 'type' => LOCATION_COUNTRY), 
     276          'conditions' => array('name LIKE' => $normalized.'%', 'type' => LOCATION_COUNTRY), 
    268277          'limit' => 10 
    269278          )); 
     
    288297        $this->redirect(404); 
    289298        break; 
     299    } 
     300    if ($isNegated && count($result)) { 
     301      $tmp = array(); 
     302      foreach ($result as $name) { 
     303        $tmp[] = '-' . $name; 
     304      } 
     305      $result = $tmp; 
    290306    } 
    291307    return $result;