| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * aPerson actions. |
|---|
| 5 | * |
|---|
| 6 | * @package cs |
|---|
| 7 | * @subpackage aPerson |
|---|
| 8 | * @author P'unk Avenue |
|---|
| 9 | * @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ |
|---|
| 10 | */ |
|---|
| 11 | class PluginaPeopleActions extends aEngineActions |
|---|
| 12 | { |
|---|
| 13 | /** |
|---|
| 14 | * Executes index action |
|---|
| 15 | * |
|---|
| 16 | * Displays a list of Persons based on the PersonTypes selected in the engine settings. |
|---|
| 17 | * |
|---|
| 18 | * @param sfRequest $request A request object |
|---|
| 19 | */ |
|---|
| 20 | public function executeIndex(sfWebRequest $request) |
|---|
| 21 | { |
|---|
| 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 | |
|---|
| 37 | $query = $this->buildQuery(); |
|---|
| 38 | $this->navChars = Doctrine::getTable('aPerson')->getAtoZ($request->getParameter('category'), null, $query); |
|---|
| 39 | $query = $this->buildQuery(); |
|---|
| 40 | $this->peopleChars = Doctrine::getTable('aPerson')->getAtoZ($request->getParameter('category'), $request->getParameter('char'), $query); |
|---|
| 41 | |
|---|
| 42 | $peopleCount = 0; |
|---|
| 43 | foreach ($this->navChars as $char => $people) |
|---|
| 44 | { |
|---|
| 45 | foreach ($people as $person) |
|---|
| 46 | { |
|---|
| 47 | $peopleCount++; |
|---|
| 48 | } |
|---|
| 49 | } |
|---|
| 50 | $this->peopleCount = $peopleCount; |
|---|
| 51 | |
|---|
| 52 | // if we are filtering by tag or by school, we want to use A-Z links as anchors |
|---|
| 53 | // otherwise, the list will be too long and we will want to browse by alpha |
|---|
| 54 | $this->anchorNavigation = ($request->hasParameter('category') || $request->hasParameter('viewAll')); |
|---|
| 55 | |
|---|
| 56 | return $this->pageTemplate; |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | public function buildQuery() |
|---|
| 60 | { |
|---|
| 61 | $query = Doctrine::getTable('aPerson') |
|---|
| 62 | ->createQuery('p') |
|---|
| 63 | ->leftJoin('p.Categories c'); |
|---|
| 64 | |
|---|
| 65 | $ids = array(); |
|---|
| 66 | foreach($this->page->Categories as $category) |
|---|
| 67 | { |
|---|
| 68 | $ids[] = $category->id; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | foreach(aPeopleTools::getAttribute('categories_filter', array()) as $id) |
|---|
| 72 | { |
|---|
| 73 | $ids[] = $id; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if(count($ids)) |
|---|
| 77 | { |
|---|
| 78 | $query->andWhereIn('c.id', $ids); |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | return $query; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Executes show action |
|---|
| 86 | * |
|---|
| 87 | * Displays more detailed information about a single Person. |
|---|
| 88 | * |
|---|
| 89 | * @param sfRequest $request A request object |
|---|
| 90 | */ |
|---|
| 91 | public function executeShow(sfWebRequest $request) |
|---|
| 92 | { |
|---|
| 93 | $this->person = Doctrine::getTable('aPerson')->findOneBySlug($request->getParameter('slug')); |
|---|
| 94 | $this->forward404Unless($this->person); |
|---|
| 95 | |
|---|
| 96 | if ($request->getParameter('slim')) |
|---|
| 97 | { |
|---|
| 98 | return $this->renderPartial('aPeople/personSlim', array('person' => $this->person)); |
|---|
| 99 | } |
|---|
| 100 | else |
|---|
| 101 | { |
|---|
| 102 | return $this->renderPartial('aPeople/person', array('person' => $this->person)); |
|---|
| 103 | } |
|---|
| 104 | // Should probably be something like this? so when slide-down ajax |
|---|
| 105 | // stuff isn't happening you get the showsuccess page |
|---|
| 106 | |
|---|
| 107 | // if ($request->getParameter('ajax')) |
|---|
| 108 | // { |
|---|
| 109 | // return $this->renderPartial('aPeople/person', array('person' => $this->person)); |
|---|
| 110 | // } |
|---|
| 111 | // else |
|---|
| 112 | // { |
|---|
| 113 | // return; |
|---|
| 114 | // } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | return $this->pageTemplate; |
|---|
| 118 | } |
|---|
| 119 | } |
|---|