Bladeren bron

卷、和期分开显示

Xiahai 8 maanden geleden
bovenliggende
commit
5f943a6986

+ 73 - 1
application/admin/controller/cms/Channel.php

@@ -126,6 +126,24 @@ class Channel extends Backend
                         $this->model->validate($validate);
                     }
                     $nameArr = array_filter(explode("\n", str_replace("\r\n", "\n", $params['name'])));
+
+                    // 获取上级是否为期刊,如是期刊则存入期刊id
+                    if ($params['channel_type'] == 'issues' || $params['channel_type'] == 'volume') {
+                        $parent_channel = \app\admin\model\cms\Channel::where(['id' => $params['parent_id']])->find();
+                        if ($params['channel_type'] == 'issues') {
+                            if ($parent_channel) {
+                                if ($parent_channel['channel_type'] == 'journal') {
+                                    $params['journal_id'] = $parent_channel['id'];
+                                }
+                            }
+                        }
+                        if ($params['channel_type'] == 'volume') {
+                            if ($parent_channel) {
+                                $params['journal_id'] = $parent_channel['journal_id'];
+                            }
+                        }
+                    }
+
                     if (count($nameArr) > 1) {
                         foreach ($nameArr as $index => $item) {
                             $itemArr = array_filter(explode('|', $item));
@@ -178,7 +196,61 @@ class Channel extends Backend
         $this->view->assign('values', $channel);
         $this->view->assign('childrenIds', $childrenIds);
         $this->assignconfig('linkdata', $linkdata);
-        return parent::edit($ids);
+
+        $row = $this->model->get($ids);
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
+            $this->error(__('You have no permission'));
+        }
+        if (false === $this->request->isPost()) {
+            $this->view->assign('row', $row);
+            return $this->view->fetch();
+        }
+        $params = $this->request->post('row/a');
+        if (empty($params)) {
+            $this->error(__('Parameter %s can not be empty', ''));
+        }
+        $params = $this->preExcludeFields($params);
+        $result = false;
+        Db::startTrans();
+        try {
+            //是否采用模型验证
+            if ($this->modelValidate) {
+                $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
+                $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
+                $row->validateFailException()->validate($validate);
+            }
+
+            // 获取上级是否为期刊,如是期刊则存入期刊id
+            if ($params['channel_type'] == 'issues' || $params['channel_type'] == 'volume') {
+                $parent_channel = \app\admin\model\cms\Channel::where(['id' => $params['parent_id']])->find();
+                if ($params['channel_type'] == 'issues') {
+                    if ($parent_channel) {
+                        if ($parent_channel['channel_type'] == 'journal') {
+                            $params['journal_id'] = $parent_channel['id'];
+                        }
+                    }
+                }
+                if ($params['channel_type'] == 'volume') {
+                    if ($parent_channel) {
+                        $params['journal_id'] = $parent_channel['journal_id'];
+                    }
+                }
+            }
+
+            $result = $row->allowField(true)->save($params);
+            Db::commit();
+        } catch (ValidateException|PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('No rows were updated'));
+        }
+        $this->success();
     }
 
     /**

+ 1 - 0
application/admin/lang/zh-cn/cms/channel.php

@@ -54,4 +54,5 @@ return [
     'Channel Type'                               => '栏目类型',
     'Journal'                                    => '期刊',
     'Issues'                                     => '卷',
+    'Volume'                                     => '期',
 ];

+ 1 - 1
application/admin/model/cms/Channel.php

@@ -170,7 +170,7 @@ class Channel extends Model
 
     public static function getChannelTypeList()
     {
-        return ['journal' => __('Journal'), 'issues' => __('Issues')];
+        return ['journal' => __('Journal'), 'issues' => __('Issues'), 'volume' => __('Volume')];
     }
 
     public static function getTypeList()

+ 1 - 1
application/admin/view/cms/channel/add.html

@@ -121,7 +121,7 @@
     <div class="form-group tf tf-channel tf tf-list">
         <label for="c-description" class="control-label col-xs-12 col-sm-2">{:__('Description')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <textarea id="c-description" data-rule="" class="form-control" name="row[description]"></textarea>
+            <textarea id="c-description" data-rule="" class="form-control editor" name="row[description]"></textarea>
         </div>
     </div>
     <div class="form-group">

+ 1 - 1
application/admin/view/cms/channel/edit.html

@@ -123,7 +123,7 @@
     <div class="form-group tf tf-channel tf tf-list">
         <label for="c-description" class="control-label col-xs-12 col-sm-2">{:__('Description')}:</label>
         <div class="col-xs-12 col-sm-8">
-            <textarea id="c-description" data-rule="" class="form-control" name="row[description]">{$row.description|htmlentities}</textarea>
+            <textarea id="c-description" data-rule="" class="form-control editor" name="row[description]">{$row.description|htmlentities}</textarea>
         </div>
     </div>
     <div class="form-group">

+ 6 - 1
public/assets/js/backend/cms/channel.js

@@ -136,7 +136,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                     },
                                     visible: function (row) {
                                         console.log(row);
-                                        if (row.type == 'channel') {
+                                        if (row.type === 'channel' || row.type === 'list') {
+                                            if (row.type === 'list') {
+                                                if (row.id === 34 || row.id === 35 || row.id === 36) {
+                                                    return false;
+                                                }
+                                            }
                                             return true;
                                         }
                                     },