1<?php 2 3/* 4 * To change this template, choose Tools | Templates 5 * and open the template in the editor. 6 */ 7 8/** 9 * Description of searchPerformancReviewAction 10 * 11 * @author nadeera 12 */ 13class searchPerformancReviewAction extends basePeformanceAction { 14 15 public $searchReviewForm; 16 private $pageNumber; 17 18 public function getPageNumber() { 19 return $this->pageNumber; 20 } 21 22 public function setPageNumber($pageNumber) { 23 $this->pageNumber = $pageNumber; 24 } 25 26 public function preExecute() { 27 $this->_checkAuthentication(); 28 } 29 30 /** 31 * 32 * @return \PerformanceReviewSearchForm 33 */ 34 public function getSearchReviewForm() { 35 if ($this->searchReviewForm == null) { 36 return new PerformanceReviewSearchForm(); 37 } else { 38 return $this->searchReviewForm; 39 } 40 } 41 42 /** 43 * 44 * @param \PerformanceReviewSearchForm $searchReviewForm 45 */ 46 public function setSearchReviewForm($searchReviewForm) { 47 $this->searchReviewForm = $searchReviewForm; 48 } 49 50 public function execute($request) { 51 52 $form = $this->getSearchReviewForm(); 53 54 $page = $request->getParameter('hdnAction') == 'search' ? 1 : $request->getParameter('pageNo', 1); 55 56 $this->setPageNumber($page); 57 58 if ($request->isMethod('post')) { 59 $form->bind($request->getParameter($form->getName())); 60 if ($form->isValid()) { 61 try { 62 63 } catch (LeaveAllocationServiceException $e) { 64 $this->templateMessage = array('WARNING', __($e->getMessage())); 65 } 66 } 67 } 68 69 $message = $this->getUser()->getFlash('templateMessage'); 70 $this->messageType = (isset($message[0])) ? strtolower($message[0]) : ""; 71 $this->message = (isset($message[1])) ? $message[1] : ""; 72 73 74 if ($this->getUser()->hasFlash('templateMessage')) { 75 $this->templateMessage = $this->getUser()->getFlash('templateMessage'); 76 $this->getUser()->setFlash('templateMessage', array()); 77 } 78 79 $form->setUser($this->getUser()); 80 $sortFeild = $request->getParameter('sortField'); 81 $sortOrder = $request->getParameter('sortOrder'); 82 $reviews = $form->searchReviews(sfConfig::get('app_items_per_page'), $page, $sortOrder, $sortFeild); 83 $countReview = $form->getCountReviewList(); 84 $this->setListComponent($reviews,$countReview); 85 $this->form = $form; 86 } 87 88 /** 89 * 90 * @param Doctrine_Collection $reviews 91 */ 92 protected function setListComponent($reviews,$countReview) { 93 $pageNumber = $this->getPageNumber(); 94 95 $configurationFactory = $this->getListConfigurationFactory(); 96 97 ohrmListComponent::setActivePlugin('orangehrmPerformancePlugin'); 98 ohrmListComponent::setConfigurationFactory($configurationFactory); 99 ohrmListComponent::setListData($reviews); 100 ohrmListComponent::setPageNumber($pageNumber); 101 ohrmListComponent::setItemsPerPage(sfConfig::get('app_items_per_page')); 102 ohrmListComponent::setNumberOfRecords($countReview); 103 } 104 105 /** 106 * 107 * @return \SearchReviewListConfigurationFactory 108 */ 109 protected function getListConfigurationFactory() { 110 return new SearchReviewListConfigurationFactory(); 111 } 112 113 protected function _checkAuthentication($request = null) { 114 $user = $this->getUser()->getAttribute('user'); 115 if (!($user->isAdmin())) { 116 $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')); 117 } 118 } 119 120 121} 122