Exemple #1
0
 /**
  * 删除模型
  */
 public function action()
 {
     $modelId = $this->isG('id', '请选择要删除的数据!');
     $model = \Model\ModelManage::findModel($modelId);
     if (empty($model)) {
         $this->error('模型不存在');
     }
     $this->db()->transaction();
     $deleteModelResult = \Model\ModelManage::deleteModel($modelId);
     if (empty($deleteModelResult)) {
         $this->db()->rollBack();
         $this->error('删除模型失败');
     }
     $deleteModelField = \Model\Field::deleteModelField($modelId);
     if (empty($deleteModelField)) {
         $this->db()->rollBack();
         $this->error('移除模型字段记录失败');
     }
     $this->db('menu')->where('menu_name = :name')->delete(['name' => $model['model_title']]);
     $this->db()->commit();
     $alterTableResult = \Model\ModelManage::alterTable(strtolower($model['model_name']));
     if (empty($alterTableResult)) {
         $log = new \Expand\Log();
         $failLog = "Alter Model Table Field: {$this->prefix}{$model['model_name']}" . date("Y-m-d H:i:s");
         $log->creatLog('modelError', $failLog);
         $this->error('删除数据库表失败,具体信息请查阅程序日志');
     }
     $this->success('删除成功');
 }
 /**
  * 添加/编辑分类
  */
 public function action()
 {
     $categoryId = $this->g('id');
     if (empty($categoryId)) {
         $this->assign('method', 'POST');
         if ($parent = $this->g('parent')) {
             $this->assign('category_parent', $parent);
             $this->assign('title', '添加子分类');
         } else {
             $this->assign('title', '添加分类');
         }
         $tree = \Model\Category::getSelectCate(array($parent));
     } else {
         $category = \Model\Category::listCategory($categoryId);
         if (empty($category)) {
             $this->error('分类不存在');
         }
         $tree = \Model\Category::getSelectCate(array($category['category_parent']));
         $this->assign('method', 'PUT');
         $this->assign($category);
         $this->assign('title', '编辑分类');
     }
     $this->assign('model', \Model\ModelManage::modelList());
     $this->assign('tree', $tree);
     $this->layout();
 }
Exemple #3
0
 /**
  * 添加模型
  */
 public function action()
 {
     $this->db()->transaction();
     /**
      * 插入模型信息
      */
     $addModelresult = \Model\ModelManage::addModel();
     if ($addModelresult === false) {
         $this->db()->rollBack();
         $this->error('添加模型失败');
     }
     /**
      * 插入模型菜单
      */
     $addMenuResult = \Model\Menu::insertModelMenu($addModelresult['lang_key'], '9', GROUP . "-{$addModelresult['model_name']}-index");
     if ($addMenuResult === false) {
         $this->db()->rollBack();
         $this->error('插入菜单失败');
     }
     /**
      * 插入初始化的字段
      */
     \Model\ModelManage::setInitField($addModelresult['model_id']);
     $this->db()->commit();
     $initResult = \Model\ModelManage::initModelTable($addModelresult['model_name']);
     $this->success('添加模型成功', $this->url(GROUP . '-Model-index'));
 }
Exemple #4
0
 /**
  * 更新模型
  */
 public function action()
 {
     $model = \Model\ModelManage::findModel($_POST['model_id']);
     \Model\ModelManage::updateModel();
     //更新菜单
     $this->db('menu')->where('menu_name = :old_name')->update(array('menu_name' => $this->p('display_name'), 'noset' => array('old_name' => $model['lang_key'])));
     $this->success('更新模型成功', $this->url(GROUP . '-Model-index'));
 }
Exemple #5
0
 /**
  * 更新模型
  */
 public function action($jump = FALSE, $commit = TRUE)
 {
     $model = \Model\ModelManage::findModel($_POST['id']);
     parent::action($jump, $commit);
     //更新菜单
     $this->db('menu')->where('menu_name = :old_name')->update(array('menu_name' => $this->p('title'), 'noset' => array('old_name' => $model['model_title'])));
     $this->success('更新模型成功', $this->url(GROUP . '-Model-index'));
 }
Exemple #6
0
 /**
  * 执行删除动作
  */
 public function delete()
 {
     $id = $this->isG('id', '请选择要删除的数据!');
     $result = \Model\ModelManage::deleteFromModelId(MODULE, $id);
     if (empty($result)) {
         $this->error('删除失败');
     } else {
         $this->success('删除成功');
     }
 }
Exemple #7
0
 public function __init()
 {
     parent::__init();
     $this->table = strtolower(MODULE);
     $this->fieldPrefix = $this->table . "_";
     $this->model = \Model\ModelManage::findModel($this->table, 'model_name');
     if (empty($this->model)) {
         $this->error('不存在的模型');
     }
     $this->assign('fieldPrefix', $this->fieldPrefix);
 }
Exemple #8
0
 /**
  * 内容排序
  */
 public function listsort()
 {
     foreach ($_POST['id'] as $key => $value) {
         \Model\ModelManage::updateSortFromModel(MODULE, $key, $value);
     }
     if (!empty($_POST['back_url'])) {
         $url = $_POST['back_url'];
     } else {
         $url = "";
     }
     $this->success('内容排序成功', $url);
 }
Exemple #9
0
 /**
  * 查找当前的分类ID
  */
 private function getCurrentCatid()
 {
     $this->catid = (int) $_GET['id'];
     if (MODULE != 'Page' && ACTION == 'view') {
         $model = strtolower(MODULE);
         $checkModel = \Model\ModelManage::findModel($model, 'model_name');
         if (!empty($checkModel)) {
             $content = \Model\Content::findContent($model, $this->catid, "{$model}_id");
             $this->catid = $content["{$model}_catid"];
         }
     }
     $this->assign('catid', $this->catid);
 }
Exemple #10
0
 /**
  * 构造函数
  */
 public function __init()
 {
     parent::__init();
     $this->model = strtolower(MODULE);
     $existModel = \Model\ModelManage::findModel($this->model, 'model_name');
     /**
      * 模型熟悉不为前台的
      * 则提示模型不存在
      */
     if ($existModel['model_attr'] != '1') {
         $this->notfound();
     }
     $this->modelInfo = $existModel;
     $this->assign('model', $this->model);
 }
Exemple #11
0
 /**
  * 更新树目录
  */
 public function listsort()
 {
     foreach ($_POST as $pk => $pv) {
         if (in_array($pk, array('tree', 'doc'))) {
             foreach ($pv as $key => $value) {
                 \Model\ModelManage::updateSortFromModel($pk, $key, $value);
             }
         }
     }
     if (!empty($_POST['back_url'])) {
         $url = $_POST['back_url'];
     } else {
         $url = $this->url('/d/manage', true);
     }
     $this->success('排序完成!', $url);
 }
Exemple #12
0
 public function __init()
 {
     parent::__init();
     //表名
     $this->table = strtolower(MODULE);
     //表前缀
     $this->fieldPrefix = $this->table . "_";
     $this->assign('fieldPrefix', $this->fieldPrefix);
     //验证模型是否存在
     $this->model = \Model\ModelManage::findModel($this->table, 'model_name');
     if (empty($this->model)) {
         $this->error('不存在的模型');
     }
     $this->modelThemePrefixPath = THEME_PATH . '/' . MODULE . '/' . MODULE;
     //获取模型的字段列表
     $fieldShowType = ACTION == 'index' ? 'field_list' : 'field_form';
     $this->field = \Model\Field::fieldList($this->model['model_id'], ['field_status' => '1', $fieldShowType => '1']);
 }
Exemple #13
0
 public function action()
 {
     $id = $this->isG('id', '请选择要删除的数据!');
     $field = \Model\Field::findField($id);
     if (empty($field)) {
         $this->error('不存在的字段');
     }
     $removeFieldResult = \Model\Field::removeField($id);
     if (empty($removeFieldResult)) {
         $this->error('删除失败');
     }
     $model = \Model\ModelManage::findModel($field['field_model_id']);
     $alertTableFieldResult = \Model\Field::alertTableField($model['model_name'], $field['field_name']);
     if (empty($alertTableFieldResult)) {
         $log = new \Expand\Log();
         $failLog = "Delete Field: " . strtolower($model['model_name']) . "_{$field['field_name']}, Model:{$model['model_name']}  " . date("Y-m-d H:i:s");
         $log->creatLog('fieldError', $failLog);
         $this->error('移除数据库表字段失败,具体信息请查阅程序日志');
     }
     $this->success('删除成功');
 }
Exemple #14
0
 /**
  * 添加模型
  */
 public function action($jump = FALSE, $commit = FALSE)
 {
     parent::action($jump, $commit);
     $modelId = $this->db()->getLastInsert;
     $modelName = $this->p('name');
     /**
      * 插入模型菜单
      */
     $addMenuResult = \Model\Menu::insertMenu(['menu_name' => $this->p('title'), 'menu_pid' => '9', 'menu_url' => GROUP . "-" . ucfirst($modelName) . "-index"]);
     if ($addMenuResult === false) {
         $this->db()->rollBack();
         $this->error('插入菜单失败');
     }
     /**
      * 插入初始化的字段
      */
     \Model\ModelManage::setInitField($modelId);
     $this->db()->commit();
     $initResult = \Model\ModelManage::initModelTable(strtolower($modelName));
     $this->success('添加模型成功', $this->url(GROUP . '-Model-index'));
 }
Exemple #15
0
 /**
  * 字段添加/编辑
  */
 public function fieldAction()
 {
     $fieldId = $this->g('id');
     $modelId = $this->isG('model', '请选择模型');
     $model = \Model\ModelManage::findModel($modelId);
     if (empty($fieldId)) {
         $this->assign('method', 'POST');
         $this->assign('title', "添加字段 - {$model['lang_key']}");
     } else {
         $field = \Model\Field::findField($fieldId);
         if (empty($field)) {
             $this->error('不存在的字段');
         }
         $this->assign($field);
         $this->assign('method', 'PUT');
         $this->assign('title', "编辑字段 - {$model['lang_key']}");
     }
     $fieldTypeOption = \Model\Option::findOption('fieldType');
     $this->assign('fieldTypeList', json_decode($fieldTypeOption['value'], true));
     $this->assign('modelId', $modelId);
     $this->layout();
 }
Exemple #16
0
 /**
  * 基础表单
  */
 public static function baseFrom()
 {
     self::$table = strtolower(MODULE);
     self::$fieldPrefix = self::$table . "_";
     self::$model = \Model\ModelManage::findModel(self::$table, 'model_name');
     $field = \Model\Field::fieldList(self::$model['model_id'], array('field_status' => '1'));
     if (self::p('method') == 'PUT') {
         $data['noset'][self::$fieldPrefix . 'id'] = self::isP('id', '丢失模型ID');
         if (!self::findContent(self::$table, $data['noset'][self::$fieldPrefix . 'id'], self::$fieldPrefix . 'id')) {
             self::error('不存在的模型');
         }
     }
     foreach ($field as $value) {
         /**
          * 判断提交的字段是否为数组
          */
         if (is_array($_POST[$value['field_name']])) {
             $_POST[$value['field_name']] = (string) implode(',', $_POST[$value['field_name']]);
         }
         /**
          * 时间转换为时间戳
          */
         if ($value['field_type'] == 'date') {
             $_POST[$value['field_name']] = (string) strtotime($_POST[$value['field_name']]);
         }
         if ($value['field_required'] == '1') {
             if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name'])) && !is_numeric($data[self::$fieldPrefix . $value['field_name']])) {
                 self::error($value['field_display_name'] . '为必填选项');
             }
         } else {
             if (!($data[self::$fieldPrefix . $value['field_name']] = self::p($value['field_name']))) {
                 $data[self::$fieldPrefix . $value['field_name']] = $value['field_default'];
             }
         }
     }
     return $data;
 }
Exemple #17
0
 /**
  * 基础表单
  */
 public static function baseForm()
 {
     if (!(self::$model = \Model\ModelManage::findModel(self::isP('model_id', '丢失模型ID')))) {
         self::error('不存在的模型');
     }
     $option = self::splitOption(self::p('option'));
     if ($option === false) {
         self::error('拆分字段选项出错');
     }
     $_POST['option'] = (string) $option;
 }
Exemple #18
0
 /**
  * 基础表单
  */
 public static function baseForm()
 {
     $data['model_id'] = self::isP('model_id', '丢失模型ID');
     if (!(self::$model = \Model\ModelManage::findModel($data['model_id']))) {
         self::error('不存在的模型');
     }
     if (self::p('method') == 'PUT') {
         $data['noset']['field_id'] = self::isP('field_id', '丢失字段ID');
         if (!self::findField($data['noset']['field_id'])) {
             self::error('不存在的模型');
         }
     } else {
         $data['field_type'] = self::isP('field_type', '请选择字段类型');
         $data['field_name'] = self::isP('field_name', '请填写字段名称');
     }
     $data['display_name'] = self::isP('display_name', '请填写字段显示名称');
     $data['field_option'] = self::splitOption();
     if ($data['field_option'] === false) {
         self::error('拆分字段选项出错');
     }
     if (!($data['field_required'] = self::p('field_required')) && !is_numeric($_POST['field_required'])) {
         return self::error('请选择是否为必填');
     }
     if (!($data['field_status'] = self::p('field_status')) && !is_numeric($_POST['field_status'])) {
         return self::error('请选择启用状态');
     }
     $data['field_default'] = self::p('field_default');
     $data['field_listsort'] = self::p('field_listsort');
     $data['field_explain'] = self::p('field_explain');
     $data['field_list'] = self::p('field_list');
     return $data;
 }
Exemple #19
0
 /**
  * 基础表单
  */
 public static function baseForm()
 {
     $data['category_parent'] = self::isP('category_parent', '请选择所属分类');
     if (!self::findCategory($data['category_parent']) && $data['category_parent'] > 0) {
         self::error('分类不存在');
     }
     $data['model_id'] = self::isP('model_id', '请选择模型');
     if (!(self::$model = \Model\ModelManage::findModel($data['model_id'])) && $data['model_id'] != '-1') {
         self::error('模型不存在');
     }
     if ($data['model_id'] == '-1') {
         $data['category_url'] = self::isP('category_url', '请填写外链地址');
     }
     if (self::p('method') == 'PUT') {
         $data['noset']['category_id'] = self::isP('category_id', '丢失编辑的ID');
     }
     $data['category_name'] = self::isP('category_name', '请填写分类名称');
     $data['category_aliases'] = self::isP('category_aliases', '请填写分类别名');
     $data['category_nav'] = self::isP('category_nav', '请选择是否为导航');
     $data['category_keyword'] = self::p('category_keyword');
     $data['category_description'] = self::p('category_description');
     $data['category_thumb'] = self::p('category_thumb');
     $data['category_listsort'] = self::p('category_listsort');
     return $data;
 }