Guest User

Controller

a guest
Jul 23rd, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.95 KB | None | 0 0
  1. <?php
  2.  
  3. class PainelClienteController extends Controller
  4. {
  5.     public $layout='//layouts/column1';
  6.  
  7.     /**
  8.      * @return array action filters
  9.      */
  10.     public function filters()
  11.     {
  12.         return array(
  13.             'accessControl', // perform access control for CRUD operations
  14.         );
  15.     }
  16.  
  17.     /**
  18.      * Specifies the access control rules.
  19.      * This method is used by the 'accessControl' filter.
  20.      * @return array access control rules
  21.      */
  22.     public function accessRules()
  23.     {
  24.         return array(
  25.             array('allow',  // allow all users to perform 'index' and 'view' actions
  26.                 'actions'=>array('index','view'),
  27.                 'users'=>array('*'),
  28.             ),
  29.             array('allow', // allow authenticated user to perform 'create' and 'update' actions
  30.                 'actions'=>array('create','update'),
  31.                 'users'=>array('@'),
  32.             ),
  33.             array('allow', // allow admin user to perform 'admin' and 'delete' actions
  34.                 'actions'=>array('admin','delete'),
  35.                 'users'=>array('admin'),
  36.             ),
  37.             array('deny',  // deny all users
  38.                 'users'=>array('*'),
  39.             ),
  40.         );
  41.     }
  42.  
  43.     /**
  44.     * This is the default 'index' action that is invoked
  45.     * when an action is not explicitly requested by users.
  46.     */
  47.     public function actionIndex()
  48.     {
  49.         $painelSelecionadoCliente = $this->selecionaPainelCliente();
  50.         $campos = new SpfRespostas;
  51.  
  52.         $this->render('painelcliente', array('painelSelecionadoCliente' => $painelSelecionadoCliente,
  53.                                              'campos'=> $campos));
  54.     }
  55.  
  56.     public function selecionaPainelCliente()
  57.     {
  58.         if(Yii::app()->request->isPostRequest)
  59.         {
  60.             $criteria = new CDbCriteria( array(
  61.                                             //'select'=>'rpc_painel_fk',
  62.                                             'with' => array('rpcPainelFk'),
  63.                                             'condition'=>'rpc_cliente_fk = :idUsuario AND
  64.                                                          rpc_painel_fk = :idPainel ',
  65.                                             'params'=>array(':idUsuario' => (int)Yii::app()->user->id,
  66.                                                             ':idPainel' => (int)$_POST['painel_id']),
  67.                                         ));
  68.  
  69.             $painelSelecionado = SpfRelPaineisClientes::model()->findAll( $criteria );
  70.  
  71.             return $painelSelecionado;
  72.         }
  73.         else
  74.             throw new CHttpException(404,'Requisição inválida.');
  75.     }
  76.  
  77.     public function buscaTendenciaPainel($painel)
  78.     {
  79.         if(Yii::app()->request->isPostRequest)
  80.         {
  81.            $criteria = new CDbCriteria( array(
  82.                                         'with' => array('rptTendenciaFk'),
  83.                                         'condition'=>'rpt_painel_fk = :idPainel',
  84.                                         'params'=>array(':idPainel' => $painel),
  85.                                     ));
  86.  
  87.             $tendenciaPainel = SpfRelPaineisTendencias::model()->findAll( $criteria );
  88.  
  89.             return $tendenciaPainel;
  90.         }
  91.         else
  92.             throw new CHttpException(404,'Requisição inválida.');
  93.     }
  94.  
  95.     public function buscaValoresEscalaPainel($escala)
  96.     {
  97.         if(Yii::app()->request->isPostRequest)
  98.         {
  99.            $criteria = new CDbCriteria( array(
  100.                                         //'with' => array('rptTendenciaFk'),
  101.                                         'condition'=>'eva_escala_fk = :idEscala',
  102.                                         'params'=>array(':idEscala' => $escala),
  103.                                     ));
  104.  
  105.             $valoresEscalasPainel = SpfEscalasValores::model()->findAll( $criteria );
  106.  
  107.             return $valoresEscalasPainel;
  108.         }
  109.         else
  110.             throw new CHttpException(404,'Requisição inválida.');
  111.     }
  112.  
  113.     public function actionAdiciona()
  114.     {
  115.         $painelSelecionado = Yii::app()->user->SessionPainelSelecionado;
  116.         $idUsuario = Yii::app()->user->id;
  117.         $model=new SpfRespostas;
  118.  
  119.         // recupera os itens para atualização em lote
  120.         // assumindo que cada item é instância de um Item
  121.         if(isset($_POST['res_resposta']))
  122.         {
  123.             $valid=true;
  124.             foreach($items as $i=>$item)
  125.             {
  126.                 if(isset($_POST['res_resposta'][$i]))
  127.                     $item->attributes=$_POST['res_resposta'][$i];
  128.                 $valid=$valid && $item->validate();
  129.             }
  130.             if($valid):  // todos os itens são validos
  131.                 // ...faça algo aqui
  132.  
  133.             endif;
  134.         }
  135.  
  136.         Yii::app()->user->setFlash('pesquisa','<span style="color: green; font-size: 20px">Sua pesquisa foi registrada com sucesso.<br /> Você está ajudando a sempre melhorarmos nossos serviços.</span>');
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment