IndexAction.php 3.07 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1 2 3
 <?php
class IndexAction extends CAction
{
Tibor Katelbach's avatar
Tibor Katelbach committed
4
    public function run($id=null, $answer=null, $mode=null)
Clément Damiens's avatar
 
Clément Damiens committed
5 6
    {
    	$this->getController()->layout = "//layouts/empty";
7
        $params = array();
Clément Damiens's avatar
 
Clément Damiens committed
8
        if(!empty($id)){
Raph El's avatar
Hotfix  
Raph El committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
            if($id == "new"){
                if(!empty(Yii::app()->session["userId"])){
 					$answer = Answer::generateAnswer();
 					$params["answerId"] = $answer["_id"];
 					$mode = "w" ;
				} else {
					if(Yii::app()->request->isAjaxRequest)
		                echo $this->getController()->renderPartial("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
		            else
		                $this->getController()->render("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));

		            exit;
				}
                
            } else {
                $params["answerId"]=$id;
                $answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
            }
Clément Damiens's avatar
 
Clément Damiens committed
27
        }
28
        //Rest::json($params); exit;
Raph El's avatar
Hotfix  
Raph El committed
29
        $params = Form::getDataForAnswer($params);
30
        $params["answer"] = $answer;
31
        // TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer
Raph El's avatar
Hotfix  
Raph El committed
32
       
33
        
Raph El's avatar
Raph El committed
34 35 36 37 38 39 40 41 42 43 44
        $form = PHDB::findOne( Form::COLLECTION , array("id"=>$answer["formId"]));
        $parentForm = Slug::getElementBySlug($form["id"]);

        $canEditAnswer = false;
        $canSeeAnswer = false;
        if(!empty(Yii::app()->session['userId'])){
            $canEditAnswer = Form::canEditAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
            if(empty($canEditAnswer)){
                $canSeeAnswer = Form::canSeeAnswer(Yii::app()->session['userId'], $params["answer"], $form, $parentForm);
                if($canSeeAnswer === true && !empty($mode) && ($mode == "w" || $mode == "rplus") )
                    $mode = "r";
Raph El's avatar
Hotfix  
Raph El committed
45 46
            }else{
            	$canSeeAnswer = true;
Raph El's avatar
Raph El committed
47 48
            }
        }
49 50
        // var_dump($canEditAnswer);
        // var_dump($canSeeAnswer);
Raph El's avatar
Raph El committed
51 52
        if($canEditAnswer === true || $canSeeAnswer === true){
            $params["canEdit"] = $canEditAnswer;
53
            $params["canSee"] = $canSeeAnswer;
Raph El's avatar
Raph El committed
54 55
            $params["mode"] = (!empty($mode) ? $mode : "r");
            //$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
Tibor Katelbach's avatar
Tibor Katelbach committed
56
            $tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
Raph El's avatar
Raph El committed
57 58
            echo $this->getController()->renderPartial($tpl,$params );
        } else {
59 60 61 62
            if(Yii::app()->request->isAjaxRequest)
                echo $this->getController()->renderPartial("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
            else
                $this->getController()->render("co2.views.default.unTpl",array("msg"=>Yii::t("common", "You are not allow to access to this answer"),"icon"=>"fa-lock"));
Raph El's avatar
Raph El committed
63 64
        }
        
Clément Damiens's avatar
 
Clément Damiens committed
65
    }
Raph El's avatar
Modif  
Raph El committed
66
}