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/sfGuardGroup/lib/BasesfGuardGroupActions.class.php');
  3.  
  4. /**
  5.  * sfGuardGroup actions.
  6.  *
  7.  * @package    sfGuardPlugin
  8.  * @subpackage sfGuardGroup
  9.  * @author     Fabien Potencier
  10.  * @version    SVN: $Id: actions.class.php 12965 2008-11-13 06:02:38Z fabien $
  11.  */
  12. class sfGuardGroupActions extends BasesfGuardGroupActions
  13. {
  14.  
  15.    public function executeView(sfWebRequest $request)
  16.    {
  17.       
  18.         $this->sfGuardGroup_tableMap sfGuardGroupPeer::getTableMap();
  19.         $this->sfGuardGroup_form new sfGuardGroupForm();
  20.    }
  21.  
  22.    public function executeRefresh(sfWebRequest $request)
  23.    {
  24.  
  25.  
  26.    }
  27.  
  28.    public function executeJsonNothing(sfWebRequest $request){
  29.  
  30.     $result array('success'=>true);
  31.     $result json_encode($result);
  32.  
  33.     $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).
  34.     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"}]}');
  35.    }
  36.  
  37.     /*
  38.      * Used in server grid to list permissions group available
  39.      * return json array response
  40.      *
  41.      */
  42.     public function executeJson(sfWebRequest $request)
  43.     {
  44.       
  45.  
  46.       $c new Criteria();    
  47.       $groups sfGuardGroupPeer::doSelect($c);
  48.       $elements array();
  49.       foreach ($groups as $group){
  50.            $elements[$group->toArray();
  51.       }
  52.  
  53.       $return array(
  54.       'data'  => $elements
  55.         );
  56.  
  57.       $result=json_encode($return);
  58.       return $this->renderText($result);
  59.     }
  60.    
  61.   public function executeJsonCreate(sfWebRequest $request)
  62.   {
  63.      $isAjax $request->isXmlHttpRequest();
  64.  
  65.      if(!$isAjaxreturn $this->redirect('@homepage');
  66.  
  67.      if(!$request->isMethod('post')){
  68.          $info array('success'=>false,'errors'=>'Wrong parameters');
  69.          $error $this->setJsonError($info);
  70.          return $this->renderText($error);
  71.      }
  72.  
  73.      $this->form new sfGuardGroupForm();
  74.  
  75.      $result $this->processJsonForm($request$this->form);
  76.  
  77.      if(!$result['success']){
  78.          $error $this->setJsonError($result);
  79.          return $this->renderText($error);
  80.      }
  81.  
  82.      $result json_encode($result);
  83.  
  84.      $this->getContext()->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).
  85.  
  86.      return $this->renderText($result);
  87.  
  88.   }
  89.  
  90.   public function executeJsonUpdate(sfWebRequest $request)
  91.   {
  92.     $isAjax $request->isXmlHttpRequest();
  93.  
  94.     if(!$isAjaxreturn $this->redirect('@homepage');
  95.  
  96.     if(!$request->isMethod('post'&& !$request->isMethod('put')){
  97.          $info array('success'=>false,'errors'=>'Wrong parameters');
  98.          $error $this->setJsonError($info);
  99.          return $this->renderText($error);
  100.     }
  101.  
  102.     if(!$sfGuardGroup sfGuardGroupPeer::retrieveByPk($request->getParameter('id'))){
  103.         $error_msg sprintf('Object sfGuardGroup does not exist (%s).'$request->getParameter('id'));
  104.         $info array('success'=>false,'errors'=>$error_msg);
  105.         $error $this->setJsonError($info);
  106.         return $this->renderText($error);
  107.     }
  108.  
  109.     $sfGuardGroup->setByName($request->getParameter('field')$request->getParameter('value'));
  110.     $sfGuardGroup->save();
  111.  
  112.     $result array('success'=>true);
  113.     $result json_encode($result);
  114.     $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).
  115.     return $this->renderText($result);
  116.  
  117.   }
  118.  
  119.   public function executeJsonDelete(sfWebRequest $request)
  120.   {
  121.     $isAjax $request->isXmlHttpRequest();
  122.  
  123.     if(!$isAjaxreturn $this->redirect('@homepage');
  124.  
  125.     if(!$sfGuardGroup sfGuardGroupPeer::retrieveByPk($request->getParameter('id'))){
  126.         $error_msg sprintf('Object sfGuardGroup does not exist (%s).'$request->getParameter('id'));
  127.         $info array('success'=>false,'errors'=>$error_msg);
  128.         $error $this->setJsonError($info);
  129.         return $this->renderText($error);
  130.     }
  131.     
  132.  
  133.     $sfGuardGroup->delete();
  134.  
  135.     $result array('success'=>true);
  136.     $result json_encode($result);
  137.     $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).
  138.     return $this->renderText($result);
  139.   }
  140.  
  141.   public function executeJsonGrid($request)
  142.   {
  143.     $isAjax $request->isXmlHttpRequest();
  144.  
  145.     if(!$isAjaxreturn $this->redirect('@homepage');
  146.  
  147.     $limit $this->getRequestParameter('limit'10);
  148.     $page floor($this->getRequestParameter('start'0$limit)+1;
  149.  
  150.     // pager
  151.     $this->pager new sfPropelPager('sfGuardGroup'$limit);
  152.     $c new Criteria();
  153.  
  154.     $this->addSortCriteria($c);
  155.     
  156.  
  157.     $this->pager->setCriteria($c);
  158.     $this->pager->setPage($page);
  159.  
  160.     $this->pager->setPeerMethod('doSelect');
  161.     $this->pager->setPeerCountMethod('doCount');
  162.  
  163.     $this->pager->init();
  164.  
  165.  
  166.     $elements array();
  167.  
  168.     # Get data from Pager
  169.     foreach($this->pager->getResults(as $item)
  170.                 $elements[$item->toArray();
  171.  
  172.     $final array(
  173.       'total' =>   $this->pager->getNbResults(),
  174.       'data'  => $elements
  175.     );
  176.  
  177.     $result json_encode($final);
  178.  
  179.     $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).
  180.     return $this->renderText($result);
  181.  
  182.   }
  183.  
  184.   protected function addSortCriteria($criteria)
  185.   {
  186.     if ($this->getRequestParameter('sort')==''return;
  187.  
  188.     $column sfGuardGroupPeer::translateFieldName(sfInflector::camelize($this->getRequestParameter('sort'))BasePeer::TYPE_PHPNAMEBasePeer::TYPE_COLNAME);
  189.  
  190.     if ('asc' == strtolower($this->getRequestParameter('dir')))
  191.       $criteria->addAscendingOrderByColumn($column);
  192.     else
  193.       $criteria->addDescendingOrderByColumn($column);
  194.   }
  195.  
  196.  
  197.   protected function processJsonForm(sfWebRequest $requestsfForm $form)
  198.   {
  199.  
  200.     $form->bind($request->getParameter($form->getName())$request->getFiles($form->getName()));
  201.  
  202.     if ($form->isValid())
  203.     {
  204.           $sfGuardGroup $form->save();
  205.  
  206.           $result array('success'=>true,'insert_id'=>$sfGuardGroup->getId());
  207.           return $result;
  208.  
  209.     }
  210.     else{
  211.         $errors array();
  212.         foreach ($form->getErrorSchema(as $field => $error)
  213.                         $errors[$field$error->getMessage();
  214.           $result array('success'=>false,'errors'=>$errors);
  215.           return $result;
  216.     }
  217.  
  218.  
  219.   }
  220.  
  221.   private function setJsonError($info,$statusCode 400){
  222.  
  223.       $this->getContext()->getResponse()->setStatusCode($statusCode);
  224.       $error json_encode($info);
  225.       $this->getContext()->getResponse()->setHttpHeader("X-JSON"'()');
  226.       return $error;
  227.  
  228.   }
  229.     
  230. }

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