sfGuardPlugin
[ class tree: sfGuardPlugin ] [ index: sfGuardPlugin ] [ all elements ]

Source for file actions.class.php

Documentation is available at actions.class.php

  1. <?php
  2. require_once(sfConfig::get('sf_plugins_dir').'/sfGuardPlugin/modules/sfGuardUser/lib/BasesfGuardUserActions.class.php');
  3.  
  4. /**
  5.  * sfGuardUser actions.
  6.  *
  7.  * @package    sfGuardPlugin
  8.  * @subpackage sfGuardUser
  9.  * @author     Fabien Potencier
  10.  * @version    SVN: $Id: actions.class.php 12965 2008-11-13 06:02:38Z fabien $
  11.  */
  12. class sfGuardUserActions extends basesfGuardUserActions
  13. {
  14.   public function executeViewer(sfWebRequest $request)
  15.   {
  16.  
  17.   }
  18.  
  19.   public function executeJsonGridInfo(sfWebRequest $request)
  20.   {
  21.     $isAjax $request->isXmlHttpRequest();
  22.  
  23.     if(!$isAjaxreturn $this->redirect('@homepage');
  24.     $elements array();
  25.     $this->sfGuardUser sfGuardUserPeer::retrieveByPk($request->getParameter('id'));
  26.  
  27.     $user_info $this->sfGuardUser->toArray();
  28.     
  29.     // returns array of profiles
  30.     $user_profiles $this->sfGuardUser->getsfGuardUserProfiles();
  31.  
  32.     // Get first profile. We only have one profile per user
  33.     $profiles $user_profiles[0]->toArray();
  34.     
  35.     $elements[array_merge($user_info,$profiles);
  36.        
  37.  
  38.     $final array('total' =>   count($elements),'data'  => $elements);
  39.     $result json_encode($final);
  40.  
  41.     $this->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  42.  
  43.     return $this->renderText($result);
  44.  
  45.   }
  46.  
  47.   public function executeJsonGrid($request)
  48.   {
  49.     $isAjax $request->isXmlHttpRequest();
  50.  
  51.     if(!$isAjaxreturn $this->redirect('@homepage');
  52.  
  53.     $limit $this->getRequestParameter('limit'10);
  54.     $page floor($this->getRequestParameter('start'0$limit)+1;
  55.  
  56.     // pager
  57.     $this->pager new sfPropelPager('sfGuardUser'$limit);
  58.     $c new Criteria();
  59.     // $c->addSelectColumn(sfGuardUserPeer::ALGORITHM);
  60.     $this->addSortCriteria($c);
  61.     // $this->addServerCriteria($c);
  62.  
  63.     $this->pager->setCriteria($c);
  64.     $this->pager->setPage($page);
  65.  
  66.     $this->pager->setPeerMethod('doSelect');
  67.     $this->pager->setPeerCountMethod('doCount');
  68.  
  69.     $this->pager->init();
  70.  
  71.  
  72.     $elements array();
  73.  
  74.  
  75.  
  76.  
  77.     # Get data from Pager
  78.     foreach($this->pager->getResults(as $item){
  79.                 $item->setAlgorithm('')// prevent algorithm value from being passed
  80.                 $elements[$item->toArray();
  81.               // $elements[] = $item;
  82.     }
  83.  
  84.  
  85. // return $this->renderText('{"metaData":{"totalProperty":"totalCount","root":"results","id":"id","fields":[{"name":"id","type":"int"},{"name":"firstname"},{"name":"lastname"},{"name":"username"},{"name":"email"},{"name":"active"},{"name":"updateTime"}]},"totalCount":1,"results":[{"id":160,"class":"TutorAccount","active":"Yes","createTime":new Date(1240424045000),"email":"wilt@moore.com","firstname":"Wsda","lastname":"Moore","note":"ssdf","password":"tota","updateTime":new Date(1240559517000),"username":"wilt"}]}');
  86.  
  87.  
  88.  
  89.  
  90.    
  91.  
  92.     $final array(
  93.       'total' =>   $this->pager->getNbResults(),
  94.       'data'  => $elements
  95.     );
  96.  
  97.  
  98.    $result $final;
  99.    $result json_encode($final);
  100.  // $result = '{"metaData":{"totalProperty":"totalCount","root":"results","id":"id","fields":[{"name":"Username"},{"name":"IsActive"},{"name":"updateTime"}]},"totalCount":1,"results":[{"id":160,"class":"TutorAccount","active":"Yes","createTime":new Date(1240424045000),"email":"wilt@moore.com","Username":"Wsda","IsActive":"Moore","note":"ssdf","password":"tota","updateTime":new Date(1240559517000),"username":"wilt"}]}';
  101.  
  102.     $this->getResponse()->setHttpHeader("X-JSON"'()')// set a header, (although it is empty, it is nicer than without a correct header. Filling the header with the result will not be parsed by extjs as far as I have seen).
  103.    return $this->renderText($result);
  104.  
  105.   }
  106.  
  107.   protected function addSortCriteria($criteria)
  108.   {
  109.     if ($this->getRequestParameter('sort')==''return;
  110.  
  111.     $column sfGuardUserPeer::translateFieldName(sfInflector::camelize($this->getRequestParameter('sort'))BasePeer::TYPE_PHPNAMEBasePeer::TYPE_COLNAME);
  112.  
  113.     if ('asc' == strtolower($this->getRequestParameter('dir')))
  114.       $criteria->addAscendingOrderByColumn($column);
  115.     else
  116.       $criteria->addDescendingOrderByColumn($column);
  117.   }
  118.   
  119. }

Documentation generated on Fri, 19 Jun 2009 10:45:49 +0100 by phpDocumentor 1.4.2