예제 #1
0
 /**
  * 
  * @return Ambigous <unknown, boolean>|Ambigous <\yii\db\static, boolean>|boolean
  */
 private function getCurrentTemplate()
 {
     if ($this instanceof Templatable) {
         $class = get_called_class();
         switch ($class::TEMPLATE_TYPE) {
             case $class::TEMPLATE_GRID:
                 return FlexgridTemplate::getCurrentFor($this->template_name);
                 break;
             case $class::TEMPLATE_FORM:
                 return FlexformTemplate::getCurrentFor($this->template_name);
                 break;
         }
         return false;
     } else {
         throw InvalidCallException('Class that uses TemplateTrait have to implement TemplatableInterface');
     }
 }
예제 #2
0
 /**
  * Method saves to template given values 
  * @throws InvalidValueException
  * @return mixed json encoded array with status 
  */
 public function actionSaveTemplate()
 {
     if (!isset($_POST['templateId'])) {
         throw new InvalidValueException("Template id missing.");
     }
     $model = FlexformTemplate::findOne($_POST['templateId']);
     foreach (\Yii::$app->request->post($model->modelClass, null) as $key => $value) {
         $field = FlexformField::find()->where(['name' => $key, 'FK_template' => $_POST['templateId']])->one();
         if (!isset($field)) {
             continue;
         }
         if (is_array($value)) {
             $field->value = implode(',', $value);
         } else {
             $field->value = $value;
         }
         $field->save();
     }
     return json_encode(['status' => 1]);
 }
예제 #3
0
 /**
  * Generates button group which represents templates panel
  * @return string generated html
  */
 private function templatesPanel()
 {
     $html = "<div id = 'template-panel-container' class = 'btn-group btn-group-justified' data-toggle= 'buttons'>";
     $userTemplatesList = FlexformTemplate::getUserFormTemplates($this->modelClass);
     foreach ($userTemplatesList as $key => $value) {
         $html .= "<label class = 'btn btn-default template-panel current-template " . ($value->current == 1 ? 'active' : '') . "' ><input type=radio name = 'currentFilter' value = {$value->id} " . ($value->current == 1 ? 'checked' : '') . ">{$value->name}</label>";
     }
     $html .= "<label class = 'btn btn-default template-panel' id = 'new-template' value = {$this->modelClass} >\n\t\t\t\t<span class = 'glyphicon glyphicon-plus'></span>\n\t\t\t\t</label>";
     $html .= "</div>";
     return $html;
 }
예제 #4
0
 public function getTemplate()
 {
     return $this->hasOne(FlexformTemplate::className(), ['id' => 'FK_template']);
 }