Commits

christiansalazar committed 64c3608

FIX ISSUE #77 - permite que searchUsersByAuthItem admita filtros de busqueda.

Comments (1)

  1. Christian Salazar repo owner

    Ejemplo de uso completo con filtros incluidos: El Controller:

        public function actionAgents(){
            $model = Yii::app()->user->um->getSearchUserModel();
                $model->unsetAttributes();
                if(isset($_GET['CrugeStoredUser']))
                        $model->attributes=$_GET['CrugeStoredUser'];
            $dataProvider = 
                Yii::app()->user->um->searchUsersByAuthItem('agent',20,null, $model);
                    /*
                           si no se quieren filtros, simplemente invocar el dataProvider asi:
                           Yii::app()->user->um->searchUsersByAuthItem('agent',20);
                    */
    
            $this->render('agents',array('model'=>$model,'dataProvider'=>$dataProvider));   
        }
    

    La vista:

    // LA VISTA:
    // $dataProvider y $model : son entregados por el controller, ver arriba el action que lo gestiona
    //
    $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'agents-grid',
        'dataProvider'=>$dataProvider,
        'filter'=>$model,
        'columns'=>array(
            array('name'=>'username'),
            array('name'=>'email'),
            array('name'=>'userdescription','filter'=>'','header'=>'Names',
                'value'=>'ucwords(strtolower($data->getUserDescription(true,\' \')))'),
            array(
                'header'=>'Actions',
                'class'=>'CLinkColumn',
                'label'=>'Edit',
                'urlExpression'=>'array(\'updateagent\',\'id\'=>$data->primarykey)'
                ),
        ),
    ));
    ?>
    

Files changed (2)

components/CrugeUserManager.php

         }
     }
 
+	public function getSearchUserModel(){
+		return CrugeFactory::get()->getICrugeStoredUserModel('search');
+	}
+
 	/**
 	  	retorna un dataprovider que contiene todos los usuarios asignados
 		directamente a un rol. (no hace busquedas recursivas)
 	 	@returns CActiveDataProvider
 	 */
 	public function searchUsersByAuthItem(
-			$authItemName, $pageSize=20, $defaultOrder=null){
-		$model = CrugeFactory::get()->getICrugeStoredUserModel('search');
+			$authItemName, $pageSize=20, $defaultOrder=null, $_model=null){
+		if($_model == null){
+		$model = $this->getSearchUserModel();
+		}else
+			$model = $_model;
 		return	$model->searchByAuthItem(
 				$authItemName, $pageSize, $defaultOrder);
 	}

models/data/CrugeStoredUser.php

 		$criteria->join = "left join ".$table_assign." ASG "
 			."on ASG.userid = t.iduser";
 		$criteria->compare("ASG.itemname",$authItemName);
+		// extra optionals, for filtering:
+        $criteria->compare('username', $this->username, true);
+        $criteria->compare('email', $this->email, true);
         return new CActiveDataProvider($this, array(
             'criteria' => $criteria,
 			'pagination' => array(