Changeset 3782

Show
Ignore:
Timestamp:
06/21/11 11:03:27 (3 years ago)
Author:
wjohnald
Message:

refactored categories filter to be saved in the session. Added a wrapper to aPeopleTools for setting and getting user attributes.

Location:
plugins/apostrophePeoplePlugin/trunk
Files:
3 added
4 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePeoplePlugin/trunk/lib/actions/PluginaPeopleActions.class.php

    r3763 r3782  
    2020  public function executeIndex(sfWebRequest $request) 
    2121  { 
     22    // Set default categories for the people sidebar as a session variable 
     23    $defaultCategories = array(); 
     24    if ($request->getParameter('aPeopleCategoryFilter')) 
     25    { 
     26      $categoryFilter = $this->getRequest()->getParameter('aPeopleCategoryFilter'); 
     27 
     28      if (!empty($categoryFilter['categories'])) 
     29      { 
     30        $defaultCategories = $categoryFilter['categories']; 
     31      } 
     32 
     33      aPeopleTools::setAttribute('categories_filter', $defaultCategories); 
     34    } 
     35 
     36 
    2237    $query = $this->buildQuery();  
    2338    $this->navChars    = Doctrine::getTable('aPerson')->getAtoZ($request->getParameter('category'), null, $query); 
     
    3954    $this->anchorNavigation = ($request->hasParameter('category') || $request->hasParameter('viewAll')); 
    4055 
    41  
    42     // Set default categories for the people sidebar 
    43     $this->defaultCategories = array(); 
    44     if ($request->getParameter('aPeopleCategoryFilter')) 
    45     { 
    46       $categoryFilter = $this->getRequest()->getParameter('aPeopleCategoryFilter'); 
    47  
    48       if (!empty($categoryFilter['categories'])) 
    49       { 
    50         $this->defaultCategories = $categoryFilter['categories']; 
    51       } 
    52     } 
    53  
    5456    return $this->pageTemplate; 
    5557  } 
     
    6668                        $ids[] = $category->id; 
    6769                } 
    68  
    69     // If the filter has been set, filter by categories 
    70     if ($this->getRequest()->hasParameter('aPeopleCategoryFilter')) 
     70     
     71    foreach(aPeopleTools::getAttribute('categories_filter', array()) as $id) 
    7172    { 
    72       $categoryFilter = $this->getRequest()->getParameter('aPeopleCategoryFilter'); 
    73  
    74       if (!empty($categoryFilter['categories'])) 
    75       { 
    76         foreach($categoryFilter['categories'] as $id) 
    77         { 
    78           $ids[] = $id; 
    79         } 
    80       } 
    81  
     73      $ids[] = $id; 
    8274    } 
    8375 
    84                 if(count($ids)) 
     76    if(count($ids)) 
    8577                { 
    8678                        $query->andWhereIn('c.id', $ids); 
  • plugins/apostrophePeoplePlugin/trunk/lib/actions/PluginaPeopleComponents.class.php

    r3763 r3782  
    2121  { 
    2222    $defaults = array(); 
    23  
    24     if (!empty($this->defaultCategories)) 
    25     { 
    26       $defaults['categories'] = $this->defaultCategories; 
    27     } 
     23    $defaults['categories'] = aPeopleTools::getAttribute('categories_filter', array()); 
    2824 
    2925    $this->form = new aPeopleCategoryForm($defaults); 
  • plugins/apostrophePeoplePlugin/trunk/lib/form/PluginaPeopleCategoryForm.class.php

    r3781 r3782  
    77 
    88 
    9     $categories = Doctrine_Query::create() 
    10       ->from('aCategory INDEXBY id') 
    11       ->select('name') 
    12       ->fetchArray(); 
     9    $categories = $this->getCategoryQuery()->fetchArray(); 
    1310 
    1411    $choices = array(); 
     
    2421    $this->widgetSchema->setNameFormat('aPeopleCategoryFilter[%s]'); 
    2522  } 
     23 
     24  public function getCategoryQuery() 
     25  { 
     26    return Doctrine_Query::create() 
     27      ->from('aCategory INDEXBY id') 
     28      ->select('name'); 
     29  } 
    2630} 
  • plugins/apostrophePeoplePlugin/trunk/modules/aPeople/templates/indexSuccess.php

    r3779 r3782  
    55        <div class="a-subnav-inner"> 
    66                <h4 class="filter-title">Filter By</h4> 
    7                 <?php include_component('aPeople', 'sidebar', array('defaultCategories' => $defaultCategories)) ?> 
     7                <?php include_component('aPeople', 'sidebar', array()) ?> 
    88        </div> 
    99</div>