From ea7aabdd3e9b45f6f202d7dd170ef0ad92f3f11d Mon Sep 17 00:00:00 2001 From: wangyidong Date: Fri, 8 Apr 2016 11:01:24 +0800 Subject: [PATCH] * add function sort and delete block. --- module/block/control.php | 51 ++++++++++++++++++++++++++++++++++++++++ module/block/model.php | 8 ------- module/common/model.php | 2 +- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/module/block/control.php b/module/block/control.php index 25b1c14804..908356f6e0 100644 --- a/module/block/control.php +++ b/module/block/control.php @@ -43,6 +43,7 @@ class block extends control $modules = $this->lang->block->moduleList; foreach($modules as $moduleKey => $moduleName) { + if($moduleKey == 'todo') continue; if(in_array($moduleKey, $this->app->user->rights['acls'])) unset($modules[$moduleKey]); if(!common::hasPriv($moduleKey, 'index')) unset($modules[$moduleKey]); } @@ -97,6 +98,56 @@ class block extends control $this->display(); } + /** + * Delete block + * + * @param int $index + * @param string $sys + * @param string $type + * @access public + * @return void + */ + public function delete($index, $module = 'my', $type = 'delete') + { + if($type == 'hidden') + { + $this->dao->update(TABLE_BLOCK)->set('hidden')->eq(1)->where('`order`')->eq($index)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); + } + else + { + $this->dao->delete()->from(TABLE_BLOCK)->where('`order`')->eq($index)->andWhere('account')->eq($this->app->user->account)->andWhere('module')->eq($module)->exec(); + } + if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $this->send(array('result' => 'success')); + } + + /** + * Sort block. + * + * @param string $oldOrder + * @param string $newOrder + * @param string $app + * @access public + * @return void + */ + public function sort($oldOrder, $newOrder, $module = 'my') + { + $oldOrder = explode(',', $oldOrder); + $newOrder = explode(',', $newOrder); + $orderList = $this->block->getBlockList($module); + + foreach($oldOrder as $key => $oldIndex) + { + if(!isset($orderList[$oldIndex])) continue; + $order = $orderList[$oldIndex]; + $order->order = $newOrder[$key]; + $this->dao->replace(TABLE_BLOCK)->data($order)->exec(); + } + + if(dao::isError()) $this->send(array('result' => 'fail')); + $this->send(array('result' => 'success')); + } + /** * Main function. * diff --git a/module/block/model.php b/module/block/model.php index d05082e77c..4626c82b53 100644 --- a/module/block/model.php +++ b/module/block/model.php @@ -111,14 +111,6 @@ class blockModel extends model ->orderBy('`order`') ->fetchAll('order'); - foreach($blocks as $key => $block) - { - if(strpos('html,allEntries,dynamic', $block->block) !== false) continue; - - $module = $block->block; - $method = 'browse'; - if(!commonModel::hasPriv($module, $method)) unset($blocks[$key]); - } return $blocks; } diff --git a/module/common/model.php b/module/common/model.php index 64e8db51a1..0f9095e267 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -160,7 +160,7 @@ class commonModel extends model if($module == 'api' and $method == 'getsessionid') return true; if($module == 'misc' and $method == 'ping') return true; if($module == 'misc' and $method == 'checktable') return true; - if($module == 'block' and $method == 'main') return true; + if($module == 'block') return true; if($module == 'sso' and $method == 'login') return true; if($module == 'sso' and $method == 'logout') return true; if($module == 'sso' and $method == 'bind') return true;