GetAction.php 1.64 KB
Newer Older
1
<?php
2
class GetAction extends CTKAction
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
{
	//if $slug : getd all the forms for an element.slug
	//if $id : opens the forms 
    public function run($form)
    {
    	
    	$controller=$this->getController();
        
    	
    	
		$controller->layout = "//layouts/empty";
		$tpl=(!empty($params["parentForm"]["answersTpl"])) ? $params["parentForm"]["answersTpl"] : 'survey.views.tpls.forms.cplx.answers';
		
		$params = [];
		$params["form"] = PHDB::findOne( Form::COLLECTION, [ "_id"=>new MongoId($form) ] );
		//var_dump($params["form"]);exit;
		$params["formList"] = $params["form"]["ids"];
		$params["forms"] = [];
		foreach ($params["formList"] as $ix => $formId) {
			$f = PHDB::findOne(Form::COLLECTION, ["id"=>$formId]);
			$params["forms"][$formId] = $f;
		}
Tibor Katelbach's avatar
Tibor Katelbach committed
25
		$params["what"] = (isset($params["form"]["what"])) ? $params["form"]["what"] : "réponses";
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
		$el = Slug::getElementBySlug( $params["form"]["parentSlug"] );
		$params['el'] = $el["el"];
		//ce code ne marchera pas pour deux formulaire identaique , d'un meme slug 
		//TODO utiliser le parntForm Id en plus 
		$params["allAnswers"] = PHDB::find( Form::ANSWER_COLLECTION, ["formId"=>implode('|', $params["form"]["ids"]) , "parentSlug" => $params["form"]["parentSlug"]] );
		$params['canEdit'] =  ( isset(Yii::app()->session["userId"])  && isset($el["type"]) && isset($el["id"]) ) ? 
	    	Authorisation::canEditItem(Yii::app()->session["userId"],$el["type"], $el["id"])
	    	: false ;
		
   		$params["wizid"] = $form;

	   	if(Yii::app()->request->isAjaxRequest)
            echo $controller->renderPartial( $tpl , $params, true);
        else
         	echo $controller->render( $tpl , $params, true);

    }
}