IndexAction.php 1.56 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 7 8 9 10
    {
    	$this->getController()->layout = "//layouts/empty";
        if(!empty($id)){
            $params["answerId"]=$id;
        }
        $params = Form::getDataForAnswer($params);
Raph El's avatar
Raph El committed
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

        // $answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($id)));
        $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";
            }
        }

        if($canEditAnswer === true || $canSeeAnswer === true){
            $params["canEdit"] = $canEditAnswer;
            $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 {
            echo "Erreur";
        }
        
Clément Damiens's avatar
 
Clément Damiens committed
38
    }
Raph El's avatar
Modif  
Raph El committed
39
}