Commit f1454983 authored by Raph El's avatar Raph El
Browse files

Form : Edit form

parent 74026502
......@@ -13,10 +13,11 @@ class NewAction extends CAction
$params["forms"] = PHDB::find(Form::COLLECTION,
array('$and' => array(
array("active" => true),
array('$or' => array(
array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1) ),
array("source.keys" => array('$in' => array($this->getController()->costum["slug"]) ) )
) )
array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1)
// array('$or' => array(
// array("parent.".$this->getController()->costum["contextId"] => array('$exists' => 1) ),
// array("source.keys" => array('$in' => array($this->getController()->costum["slug"]) ) )
// ) )
)),
array("name") ) ;
}
......
<?php
class EditAction extends CAction
{
public function run($id=null, $answer=null, $tpl=null)
public function run($id=null, $answer=null)
{
$this->getController()->layout = "//layouts/empty";
$params = array("canEdit" => true, "showAnswerActions"=>false);
$params = Form::getDataForAnswer($params);
$tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.views.index";
$params["mode"]="w";
echo $this->getController()->renderPartial($tpl,$params );
// $this->getController()->layout = "//layouts/empty";
// $params = array("canEdit" => true, "showAnswerActions"=>false);
// $params = Form::getDataForAnswer($params);
// $tpl=(!empty($tpl)) ? $tpl : "survey.views.tpls.views.index";
// $params["mode"]="w";
// echo $this->getController()->renderPartial($tpl,$params );
$this->getController()->layout = "//layouts/empty";
$params = array();
if(!empty($id) && !empty(Yii::app()->session["userId"]) ){
$form = PHDB::findOneById( Form::COLLECTION , $id);
$canEditForm = Form::canAdmin(Yii::app()->session['userId'], $form);
if($canEditForm === true){
if(!empty($answer)){
$params["answerId"]=$answer;
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("_id"=>new MongoId($answer)));
} else {
$answer = PHDB::findOne( Form::ANSWER_COLLECTION, array("form"=>$id, "draft" => true));
if(empty($answer))
$answer = Answer::generateAnswer($form, true);
$params["answerId"] = (String) $answer["_id"];
}
$params["form"] = $form ;
//Rest::json($params); exit;
$params = Form::getDataForAnswer($params);
$params["answer"] = $answer;
$params["canEditForm"] = $canEditForm;
$params["canEdit"] = true;
$params["canSee"] = true;
$params["showForm"] = true;
$params["mode"] = "fa";
$tpl=(!empty($this->getController()->costum["form"]["tpl"])) ? $this->getController()->costum["form"]["tpl"] : "survey.views.tpls.forms.formWizard";
echo $this->getController()->renderPartial($tpl,$params );
} 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"));
}
} 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"));
}
}
}
......
......@@ -10,7 +10,7 @@ class Answer{
}
public static function generateAnswer($form){
public static function generateAnswer($form, $draft = false){
$costum = CacheHelper::getCostum();
//Rest::json($costum); exit;
$ans = [
......@@ -22,6 +22,8 @@ class Answer{
],
"created" => time()
];
if($draft === true)
$ans["draft"] = true;
$formList = null ;
if( !empty($form) ){
......
......@@ -38,6 +38,9 @@ foreach ($forms as $fix => $f) {
<a href='javascript:;' data-id='<?php echo $fix ?>' class="configBtn btn btn-xs btn-danger col-sm-4 col-sm-12 bold">
<i class='fa fa-cogs'></i> CONFIG
</a>
<a target='_blank' href='costum/co/index/slug/<?php echo $el["slug"] ?>#form.edit.id.<?php echo $fix ?>' class="btn btn-xs btn-primary col-sm-4 col-xs-12 bold">
<i class='fa fa-file-text-o'></i> Edit Form
</a>
<a target='_blank' href='costum/co/index/slug/<?php echo $el["slug"] ?>#answer.index.id.new.form.<?php echo $fix ?>' class="btn btn-xs btn-primary col-sm-4 col-xs-12 bold">
<i class='fa fa-file-text-o'></i> RÉPONDRE
</a>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment