Beispiel #1
0
 /**
  * @param Entity_Item $item
  * @return bool
  */
 public function update($item)
 {
     $id = $item->getId();
     $f = $item->getF();
     $stmt = $this->DB->prepare('UPDATE `site_item` SET
                                 `item_f`=:f
                                 WHERE `item_id`=:id');
     $stmt->bindParam(':id', $id);
     $stmt->bindParam(':f', $f);
     return $stmt->execute();
 }
Beispiel #2
0
 /**
  * @param int $id
  * @return String
  */
 public function getItem($id = null)
 {
     $id = $this->isAjax() ? intval($_POST['id']) : $id;
     $tree = $this->itemModel->getItem($id);
     $entity = new Entity_Item();
     $entity->init($tree);
     $toReplace = array('{action}', '{tree_title}', '{tree_name}', '{tree_pid}', '{id_value}', '{f_value}');
     $replace = array(empty($id) ? 'add' : 'update', $tree['title'], $tree['name'], empty($id) ? intval($_POST['pid']) : $tree['pid'], $tree['id'], $entity->getF());
     $typeModel = new Admin_Models_Type();
     $type = $typeModel->getTypeByName('item');
     $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/item.tpl');
     $result = str_replace($toReplace, $replace, $file);
     if ($this->isAjax()) {
         $this->putAjax($result);
     }
     return $result;
 }