IndexAction.php 2.23 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1 2 3
 <?php
class IndexAction extends CAction
{
Raph El's avatar
Modif  
Raph El committed
4
    public function run($id=null, $answer=null, $tpl=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 9 10 11
        if(!empty($id)){
            $params["answerId"]=$id;
        }
        $params = Form::getDataForAnswer($params);
Raph El's avatar
Raph El committed
12

13 14 15 16 17

        // TODO améliorer getdataForAnser pour soit viré la création de lanswers soit charger la bonne answer

        $answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
        $params["answer"] = $answer;
Raph El's avatar
Raph El committed
18 19 20 21 22 23 24 25 26 27 28 29 30
        $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";
            }
        }
31 32
        // var_dump($canEditAnswer);
        // var_dump($canSeeAnswer);
Raph El's avatar
Raph El committed
33 34
        if($canEditAnswer === true || $canSeeAnswer === true){
            $params["canEdit"] = $canEditAnswer;
35
            $params["canSee"] = $canSeeAnswer;
Raph El's avatar
Raph El committed
36 37 38 39 40 41
            $params["mode"] = (!empty($mode) ? $mode : "r");
            //Rest::json($params); exit;
            //$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.forms.formWizard";
            $tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.views.index";
            echo $this->getController()->renderPartial($tpl,$params );
        } else {
42 43 44 45
            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
46 47
        }
        
Clément Damiens's avatar
 
Clément Damiens committed
48
    }
Raph El's avatar
Modif  
Raph El committed
49
}