Exemple #1
0
 /**
  * @param int $id
  * @return String
  */
 public function getBlock($id = null)
 {
     $id = $this->isAjax() ? intval($_POST['id']) : $id;
     $tree = $this->blockModel->getBlock($id);
     $entity = new Entity_Block();
     $entity->init($tree);
     $toReplace = array('{action}', '{tree_title}', '{tree_name}', '{tree_pid}', '{id_value}', '{side_value}', '{text_value}', '{is_text_value}', '{choiceFile}', '{uniqID}');
     $choice = new Admin_Controllers_ChoiceFile(false);
     $replace = array(empty($id) ? 'add' : 'update', $tree['title'], $tree['name'], empty($id) ? intval($_POST['pid']) : $tree['pid'], $tree['id'], $entity->getSide(), $entity->getText(), $entity->getIs_text(), $choice->genHTML(), uniqid());
     $typeModel = new Admin_Models_Type();
     $type = $typeModel->getTypeByName('block');
     $fields = json_decode($type->getJson(), true);
     $cnt = count($fields);
     if (empty($id)) {
         for ($i = 0; $i < $cnt; $i++) {
             $cntJ = count($fields[$i]['variants']);
             for ($j = 0; $j < $cntJ; $j++) {
                 $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}';
                 $replace[] = $fields[$i]['selects'] == $j ? $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"' : '';
             }
         }
     } else {
         for ($i = 0; $i < $cnt; $i++) {
             $cntJ = count($fields[$i]['variants']);
             $str = 'get' . ucfirst($fields[$i]['name']);
             $arr = explode(',', $entity->{$str}());
             for ($j = 0; $j < $cntJ; $j++) {
                 $toReplace[] = '{' . $fields[$i]['name'] . '_' . $j . '_value}';
                 if (in_array($fields[$i]['variants'][$j], $arr)) {
                     $replace[] = $fields[$i]['type'] == 'select' ? 'selected="selected"' : 'checked="checked"';
                 } else {
                     $replace[] = '';
                 }
             }
         }
     }
     $file = file_get_contents(ADMIN . '/views/types/block.tpl');
     $result = str_replace($toReplace, $replace, $file);
     if ($this->isAjax()) {
         $this->putAjax($result);
     }
     return $result;
 }