Exemple #1
0
 public function proc_upd()
 {
     if (system::action() == "proc_upd") {
         $obj = new ormFieldsGroup($_POST['obj_id']);
     } else {
         if (system::action() == "proc_add") {
             $obj = new ormFieldsGroup();
             $obj->setClassId($_POST['obj_id']);
         }
     }
     $obj->setName(system::POST('group_name'));
     $obj->setSName(system::POST('group_sname'));
     $obj->setView(system::POST('group_view'));
     $obj->setSystem(system::POST('group_system'));
     $obj_id = $obj->save();
     if ($obj_id === false) {
         echo json_encode(array('error' => 1, 'data' => $obj->getErrorListText(' ')));
     } else {
         $tree = new ormFieldsTree();
         $forUpd = system::action() == "proc_add" ? 0 : 1;
         echo json_encode(array('error' => 0, 'data' => $tree->getGroupHTML($obj, $forUpd)));
     }
     system::stop();
 }
Exemple #2
0
    private function createClass()
    {
        $sql = 'SELECT count(c_id)
  					 FROM <<classes>>
        			 WHERE c_sname = "' . $this->sname . '";';
        if (db::q($sql, value) == 0) {
            $nul = $this->base_class == NULL ? '' : 'c_base_class = "' . $this->base_class . '",';
            $nul .= $this->parent_id == NULL ? '' : 'c_parent_id = "' . $this->parent_id . '",';
            $parent = $this->getParent();
            $this->is_page = $parent instanceof ormClass ? $parent->isPage() : 0;
            $sql = 'INSERT INTO <<classes>>
						SET c_name = "' . $this->name . '",
							c_sname = "' . $this->sname . '",
							' . $nul . '
							c_text = "' . $this->padej . '",
							c_system = "' . $this->system . '",
							c_is_list = "' . $this->is_list . '",
							c_is_page = "' . $this->is_page . '";';
            $this->id = db::q($sql);
            if ($this->id !== false) {
                $sql = 'CREATE TABLE <<__' . $this->sname . '>> (
							`obj_id` INT( 11 ) NOT NULL
							) ENGINE=InnoDB;';
                if (db::q($sql) !== false) {
                    db::q('ALTER TABLE <<__' . $this->sname . '>>
                         		ADD CONSTRAINT <<__' . $this->sname . '_fk_obj_id>>
                         		FOREIGN KEY (`obj_id`)
                         		REFERENCES <<objects>> (`o_id`)
                         		ON DELETE CASCADE ON UPDATE CASCADE');
                    // Регистрация класса в коллекции
                    ormClasses::registration($this);
                    // Наследует все поля родительского класса
                    if ($parent instanceof ormClass) {
                        $groups = $parent->getAllGroups();
                        if (!empty($groups)) {
                            while (list($key, $gval) = each($groups)) {
                                $parentGroup = new ormFieldsGroup($gval['fg_id']);
                                $group = clone $parentGroup;
                                $group->setClassId($this->id);
                                $gid = $group->save();
                                if ($gid !== false) {
                                    $fields = $parentGroup->getAllFields(1);
                                    while (list($key, $fval) = each($fields)) {
                                        $field = clone new ormField($fval['f_id']);
                                        $field->setGroupId($gid);
                                        $field->save();
                                    }
                                }
                            }
                        }
                    } else {
                        // Класс сам по себе, создаем группу и поле по умолчанию
                        $group = new ormFieldsGroup();
                        $group->setName('Основное');
                        $group->setSName('base');
                        $group->setView(1);
                        $group->setSystem(1);
                        $group->setClassId($this->id);
                        $gid = $group->save();
                        if ($gid !== false) {
                            $field = new ormField();
                            $field->setName('Название');
                            $field->setSName('name');
                            $field->setType(10);
                            $field->setView(1);
                            $field->setSearch(0);
                            $field->setInherit(1);
                            $field->setFilter(0);
                            $field->setRequired(1);
                            $field->setSystem(0);
                            $field->setUniqum(0);
                            $field->setGroupId($gid);
                            $field->save();
                        }
                    }
                    return $this->id;
                } else {
                    $this->newError(27, 'Невозможно создать таблицу данных класса!');
                    return false;
                }
            } else {
                $this->newError(12, 'Ошибка в SQL запросе!');
                return false;
            }
        } else {
            $this->newError(26, 'Класс с указанным системным именем уже существует в системе!');
            return false;
        }
    }