コード例 #1
0
ファイル: ormObject.php プロジェクト: sunfun/Bagira.CMS
 public function copy($with_child = true, $copyTo = 0)
 {
     if (!empty($this->id)) {
         $copy = new ormObject();
         $copy->setClass($this->getClass()->id());
         // Перенос данных полей
         $fields = $this->getClass()->loadFields();
         while (list($fname, $field) = each($fields)) {
             if (!empty($field['f_type']) && $field['f_type'] != 97 && $field['f_relation'] < 2) {
                 $copy->__set($fname, $this->__get($fname));
             }
         }
         if (empty($copyTo)) {
             $copy->__set('name', $this->__get('name') . lang::get('copy'));
         }
         // Устанавливаем родителя
         if (empty($copyTo)) {
             $parents = $this->getParents();
             while (list($id, $parent) = each($parents)) {
                 $copy->setNewParent($id);
             }
         } else {
             $copy->setNewParent($copyTo);
         }
         $copy->save();
         if (!$copy->issetErrors() && $with_child) {
             while ($child = $this->getChild()) {
                 $child->copy(true, $copy->id);
             }
             return true;
         } else {
             if ($copy->issetErrors()) {
                 return false;
             }
         }
     }
 }
コード例 #2
0
ファイル: ormMultiForm.php プロジェクト: sunfun/Bagira.CMS
 /**
  * @return null
  * @param string $callback - Имя php-функции для обработки добавления/изменения объектов.
  * @desc Сохраняет все пришедшие данные. Метод используется обработчиком формы.
  */
 public function process($callback = '', $addit_parram = '')
 {
     if (isset($_POST['obj' . $this->form_name]) && isset($_POST['class_' . $this->form_name])) {
         $class = ormClasses::get($_POST['class_' . $this->form_name]);
         $mas = $class->loadFields();
         while (list($id, $fields) = each($_POST['obj' . $this->form_name])) {
             $keys = array_keys($fields);
             if (is_numeric($id)) {
                 $obj = ormObjects::get($id);
             } else {
                 if (!$this->without_add && !empty($fields[$keys[0]])) {
                     $obj = new ormObject();
                     $obj->setClass($class->getSName());
                 }
             }
             if (isset($obj) && $obj instanceof ormObject) {
                 if (!$this->without_del && isset($_POST['delete_' . $obj->id])) {
                     $obj->toTrash();
                 } else {
                     reset($mas);
                     while (list($key, $f_val) = each($mas)) {
                         if ($f_val['f_type'] > 89 && $f_val['f_type'] < 101 && $f_val['f_relation'] == 2 && isset($fields[$key])) {
                             // Справочник с типом "Выбор родителя"
                             $obj->clearParents();
                             $ps = $obj->getParents();
                             $parents = $fields[$key];
                             if (!empty($parents)) {
                                 if (is_numeric($parents) && !empty($parents)) {
                                     $pos = isset($ps[$parents]) ? $ps[$parents]['position'] : 0;
                                     $obj->setNewParent($parents, $pos);
                                 } else {
                                     if (is_array($parents)) {
                                         while (list($key, $val) = each($parents)) {
                                             if (!empty($val)) {
                                                 $pos = isset($ps[$val]) ? $ps[$val]['position'] : 0;
                                                 $obj->setNewParent($val, $pos);
                                             }
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($f_val['f_type'] == 50 && !isset($fields[$key])) {
                                 // Галочка
                                 $obj->__set($key, false);
                             } else {
                                 if (isset($fields[$key])) {
                                     // Дополнительная проверка для файловых полей
                                     if ($f_val['f_type'] > 69 && $f_val['f_type'] < 86) {
                                         if (!empty($_FILES['file_obj' . $this->form_name]['tmp_name'][$id][$key])) {
                                             // Создаем переменную обманку, чтобы объект сам обработал файл
                                             $file = array('name' => $_FILES['file_obj' . $this->form_name]['name'][$id][$key], 'type' => $_FILES['file_obj' . $this->form_name]['type'][$id][$key], 'tmp_name' => $_FILES['file_obj' . $this->form_name]['tmp_name'][$id][$key], 'error' => $_FILES['file_obj' . $this->form_name]['error'][$id][$key], 'size' => $_FILES['file_obj' . $this->form_name]['size'][$id][$key]);
                                             $_FILES['file_' . $key] = $file;
                                         }
                                     }
                                     $obj->__set($key, $fields[$key]);
                                 } else {
                                     if (!empty($fields[$key . '_date']) && isset($fields[$key . '_time'])) {
                                         $datetime = $fields[$key . '_date'] . ' ' . $fields[$key . '_time'] . ':00';
                                         $obj->__set($key, $datetime);
                                     }
                                 }
                             }
                         }
                     }
                     if (!empty($callback) && function_exists($callback)) {
                         $is_ok = call_user_func($callback, $obj, $addit_parram);
                     } else {
                         $is_ok = true;
                     }
                     if ($is_ok) {
                         $is_ok = $obj->save();
                     }
                     if ($is_ok === false) {
                         // echo $obj->getErrorListText();
                         system::savePostToSession();
                         ui::MessageBox(lang::get('TEXT_MESSAGE_ERROR'), $obj->getErrorListText());
                         //ui::selectErrorFields($obj->getErrorFields());
                     }
                     unset($obj);
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: ormPage.php プロジェクト: sunfun/Bagira.CMS
    public function __set($name, $value)
    {
        if ($this->isSysField($name)) {
            $this->new_prop[$name] = system::checkVar($value, isInt);
        } else {
            if ($name == 'pseudo_url') {
                // Проверка уникальности Псевдоурла
                $pseudo_url = system::checkVar($value, isPseudoUrl);
                if ($pseudo_url !== false) {
                    $parent_id = $this->getParentId();
                    $s = empty($this->id) ? '' : 'p_obj_id <> "' . $this->id . '" and ';
                    $s .= empty($parent_id) ? 'r_parent_id is NULL' : 'r_parent_id = "' . $parent_id . '"';
                    $sql = 'SELECT count(p_obj_id) FROM <<pages>>, <<objects>>, <<rels>>
							WHERE pseudo_url = "' . $pseudo_url . '" and
								  lang_id = "' . languages::curId() . '" and
								  domain_id = "' . domains::curId() . '" and
								  r_children_id = p_obj_id and ' . $s . ' and
								  o_id = p_obj_id and
								  o_to_trash = 0;';
                    $count = db::q($sql, value);
                    if ($count > 0) {
                        $this->newError(46, 'В текущем разделе уже есть объект с указанным псевдо адресом.', 'pseudo_url');
                        return false;
                    }
                } else {
                    $this->newError(47, 'Неправильно указан псевдо адрес!', 'pseudo_url');
                    return false;
                }
            } else {
                if ($name == 'is_home_page') {
                    // Смотрим можно ли поменять свойство "домашняя страница"
                    $value = system::checkVar($value, isBool);
                    if (!$value && isset($this->cur_prop[$name]) && $this->cur_prop[$name]) {
                        $value = true;
                    }
                }
            }
            return parent::__set($name, $value);
        }
    }