GetAction.php 2.39 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($slug = null,$form=null)
    {
    	
    	$controller=$this->getController();
        
    	
    	if(!empty($slug)){
    		$controller->layout = "//layouts/empty";
    		$tpl = 'survey.views.tpls.forms.oforms';
	   		$el = Slug::getElementBySlug($slug);
	   		$params = [ "el"=>$el["el"] ];
	   		$params["forms"] = PHDB::find( Form::COLLECTION, [ "parentSlug"=>$slug ] );
	   		
			//$params["forms"][0]["name"] = "todo COForms name";
			//var_dump($el["el"]["costum"]["form"]); exit;
			if(isset($params["forms"]))
			{
				foreach ( $params["forms"] as $fix => $f ) 
				{
Tibor Katelbach's avatar
Tibor Katelbach committed
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
					$formId = "";
					if(isset($f['ids'])){
						foreach ($f['ids'] as $ix => $fid) 
						{
							if($formId != "")
								$formId .= "|";
							$formId .= $fid;
							$params["forms"][$fix][$fid] = PHDB::findOne( Form::COLLECTION, [ "id"=>$fid ] );
						}
					}
					$params["forms"][$fix]["answers"] = PHDB::count( Form::ANSWER_COLLECTION, ["formId"=>$formId , "parentSlug" => $slug] );
				}
			}

	   	} 
	   	// IS IT IMPORTANT TO OPEN A FORM WITHOUT AN ANSWER
	   	// else if(!empty($form))
	   	// {
	   	// 	$controller->layout = "//layouts/mainSearch";
	   	// 	$canEdit = false;

	    //     if( isset(Yii::app()->session["userId"])  && isset($controller->costum["contextType"]) && isset($controller->costum["contextId"]) )
	    //         $canEdit = Authorisation::canEditItem(Yii::app()->session["userId"],@$controller->costum["contextType"], @$controller->costum["contextId"]);
	        
	    //     //TODO if no canEdit et test exist then 
	    //       //redirect unTpl 

	    //     $params = ["canEdit" => $canEdit];
	    //     if( isset($test) ){
	    //         $params["tpl"]=$id;
	    //         $params["test"]=$test;
	    //     }

	    //     if(isset($_GET["form"]))
	    //         $params = Form::getDataForAnswer($params);

	    //     $params['el'] = Slug::getElementBySlug( $params["parentForm"]["parentSlug"] )["el"];

	    //     $tpl=(!empty($params["parentForm"]["tpl"])) ? $params["parentForm"]["tpl"] : "survey.views.tpls.forms.formWizard";
	   	// }

	   	//var_dump($params);exit;

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

    }
}