DirectoryAction.php 1.65 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
<?php 
 /**
  * Display the directory of back office
  * @param String $id Not mandatory : if specify, look for the person with this Id. 
  * Else will get the id of the person logged
  * @return type
  */
class DirectoryAction extends CAction
{
	public function run( $slug=null, $tpl=null, $view=null ){
		$controller = $this->getController();
		$panelAdmin = $_POST;
		$limitMin=0;
		$stepLim=100;
		if(@$_POST["page"]){
			$limitMin=$limitMin+(100*($_POST["page"]-1));
		}
		$search="";
		if(!empty($_POST["name"])){
			$search = trim(urldecode($_POST['name']));
		}

		$panelAdmin["context"] = array(	"id" => $_POST["id"], 
										"collection" => $_POST["collection"], 
										"slug" => $_POST["slug"] );

		$searchRegExp = Search::accentToRegex($search);
		$query=array("parentSlug"=>$slug);
		$querySearch =  array();
		if(!empty($querySearch))
			$query = array('$and' => array( $query , $querySearch ) ) ;

		if(!empty($panelAdmin['filters'])){
			$query = Search::searchFilters($panelAdmin['filters'], $query);
		}
		
		$params["typeDirectory"]=[ Form::ANSWER_COLLECTION ];
		$params["results"] = array();
		$answers = PHDB::findAndLimitAndIndex ( Form::ANSWER_COLLECTION , $query, $stepLim, $limitMin);
		$answerList = Form::listForAdmin($answers) ;

		$params["results"]["count"][Form::ANSWER_COLLECTION] = PHDB::count( Form::ANSWER_COLLECTION , $query);

		$params["results"][Form::ANSWER_COLLECTION] = $answerList ;
		$params["panelAdmin"] = $panelAdmin;
		$page = "groupAdmin";
		if($tpl=="json")
			Rest::json( $params );
		else if(Yii::app()->request->isAjaxRequest)
			echo $controller->renderPartial("costum.views.custom.default.".$page,$params,true);
		
		
	}
}