| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?php
- /**
- * The model file of block module of ZenTaoPMS.
- *
- * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
- * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
- * @author Yidong Wang <yidong@cnezsoft.com>
- * @package block
- * @version $Id$
- * @link https://www.zentao.net
- */
- class blockModel extends model
- {
- /**
- * 检查ZDOO请求时发起的哈希值是否匹配。
- * Check if the hash value matches when requesting ZDOO.
- *
- * @param string $hash
- * @access public
- * @return bool
- */
- public function checkAPI($hash)
- {
- if(empty($hash)) return false;
- $key = $this->dao->select('value')->from(TABLE_CONFIG)
- ->where('owner')->eq('system')
- ->andWhere('module')->eq('sso')
- ->andWhere('`key`')->eq('key')
- ->fetch('value');
- return $key == $hash;
- }
- /**
- * 根据区块ID获取区块信息。
- * Get a block by id.
- *
- * @param int $blockID
- * @access public
- * @return object|false
- */
- public function getByID($blockID)
- {
- if(!$blockID) return false;
- $block = $this->dao->select('*')->from(TABLE_BLOCK)->where('id')->eq($blockID)->fetch();
- if(empty($block)) return false;
- $block->params = json_decode($block->params);
- if(empty($block->params)) $block->params = new stdclass();
- if($block->code == 'html') $block->params->html = $this->loadModel('file')->setImgSize($block->params->html);
- return $block;
- }
- /**
- * 获取被永久关闭的区块数据。
- * Get closed block pairs.
- *
- * @param string $closedBlock
- * @access public
- * @return array
- */
- public function getClosedBlockPairs($closedBlock)
- {
- $blockPairs = array();
- if(empty($closedBlock)) return $blockPairs;
- foreach(explode(',', $closedBlock) as $block)
- {
- $block = trim($block);
- if(empty($block)) continue;
- list($moduleName, $blockKey) = explode('|', $block);
- if($moduleName == $blockKey)
- {
- $blockPairs[$block] = zget($this->lang->block->moduleList, $moduleName);
- }
- else
- {
- $blockName = $blockKey;
- if(isset($this->lang->block->modules[$moduleName]->availableBlocks[$blockKey])) $blockName = $this->lang->block->modules[$moduleName]->availableBlocks[$blockKey];
- if(isset($this->lang->block->availableBlocks[$blockKey])) $blockName = $this->lang->block->availableBlocks[$blockKey];
- $moduleName = zget($this->lang->block->moduleList, $moduleName);
- $blockPairs[$block] = "{$moduleName}|{$blockName}";
- }
- }
- return $blockPairs;
- }
- /**
- * 获取当前用户的区块列表。
- * Get block list of current user.
- *
- * @param string $module
- * @param int $hidden
- * @access public
- * @return array|false
- * @param string $dashboard
- */
- public function getMyDashboard($dashboard)
- {
- return $this->dao->select('*')->from(TABLE_BLOCK)
- ->where('account')->eq($this->app->user->account)
- ->andWhere('dashboard')->eq($dashboard)
- ->andWhere('hidden')->eq(0)
- ->andWhere('vision')->eq($this->config->vision)
- ->orderBy('width_desc,top_asc,id_asc')
- ->fetchAll('', false);
- }
- /**
- * 根据区块索引获取靠后的一个区块ID。
- * Get my block id by block code,
- *
- * @param string $dashboard
- * @param string $module
- * @param string $code
- * @access public
- * @return int|false
- */
- public function getSpecifiedBlockID($dashboard, $module, $code)
- {
- if(!$dashboard || !$module || !$code) return false;
- $blockID = $this->dao->select('id')->from(TABLE_BLOCK)
- ->where('account')->eq($this->app->user->account)
- ->andWhere('dashboard')->eq($dashboard)
- ->andWhere('module')->eq($module)
- ->andWhere('code')->eq($code)
- ->orderBy('id_desc')
- ->limit(1)
- ->fetch('id');
- return $blockID ? $blockID : false;
- }
- /**
- * 获取区块是否已经初始化的状态。
- * get block is initiated or not.
- *
- * @param string $dashboard
- * @access public
- * @return bool
- */
- public function getBlockInitStatus($dashboard)
- {
- if(!$dashboard) return false;
- $result = $this->dao->select('value')->from(TABLE_CONFIG)
- ->where('module')->eq($dashboard)
- ->andWhere('owner')->eq($this->app->user->account)
- ->andWhere('`section`')->eq('common')
- ->andWhere('`key`')->eq('blockInited')
- ->andWhere('vision')->eq($this->config->vision)
- ->fetch('value');
- return !empty($result);
- }
- /**
- * 新增一个区块。
- * Create a block.
- *
- * @param object $formData
- * @access public
- * @return int
- */
- public function create($formData)
- {
- $this->dao->insert(TABLE_BLOCK)->data($formData)
- ->autoCheck()
- ->batchCheck($this->config->block->create->requiredFields, 'notempty')
- ->exec();
- if(dao::isError()) return false;
- return (int)$this->dao->lastInsertID();
- }
- /**
- * 修改一个区块。
- * Update a block.
- *
- * @param object $formData
- * @access public
- * @return int|false
- */
- public function update($formData)
- {
- $this->dao->update(TABLE_BLOCK)->data($formData)
- ->where('id')->eq($formData->id)
- ->autoCheck()
- ->batchCheck($this->config->block->edit->requiredFields, 'notempty')
- ->exec();
- if(dao::isError()) return false;
- return (int)$formData->id;
- }
- /**
- * 对应仪表盘删除所有区块并更新为待初始化状态。
- * Reset dashboard blocks.
- *
- * @param string $dashboard
- * @access public
- * @return bool
- */
- public function reset($dashboard)
- {
- /* 删除当前仪表盘下该用户的所有区块。 */
- $this->dao->delete()->from(TABLE_BLOCK)
- ->where('dashboard')->eq($dashboard)
- ->andWhere('vision')->eq($this->config->vision)
- ->andWhere('account')->eq($this->app->user->account)
- ->exec();
- /* 重置初始化状态为未初始化。 */
- $this->dao->delete()->from(TABLE_CONFIG)
- ->where('module')->eq($dashboard)
- ->andWhere('vision')->eq($this->config->vision)
- ->andWhere('owner')->eq($this->app->user->account)
- ->andWhere('`key`')->eq('blockInited')
- ->exec();
- return !dao::isError();
- }
- /**
- * 根据ID删除一个区块或者根据代号删除多个区块。
- * Delete a block based on id or multiple blocks based on code.
- *
- * @param int $blockID
- * @access public
- * @return bool
- * @param string $module
- * @param string $code
- */
- public function deleteBlock($blockID = 0, $module = '', $code = '')
- {
- /* 指定BlockID时删除该区块,指定module和code时候会删除所有人的区块。 */
- $this->dao->delete()->from(TABLE_BLOCK)
- ->where('1=1')
- ->beginIF($blockID)
- ->andWhere('id')->eq($blockID)
- ->andWhere('account')->eq($this->app->user->account)
- ->andWhere('vision')->eq($this->config->vision)
- ->fi()
- ->beginIF($module && $code)
- ->andWhere('module')->eq($module)
- ->andWhere('code')->eq($code)
- ->fi()
- ->exec();
- return !dao::isError();
- }
- /**
- * 计算区块距离顶部的高度。
- * compute block top height.
- *
- * @param object $block
- * @access public
- * @return int
- */
- public function computeBlockTop($block)
- {
- $top = $this->dao->select('max(`top` + `height`) AS top')->from(TABLE_BLOCK)
- ->where('dashboard')->eq($block->dashboard)
- ->andWhere('width', true)->eq($block->width)
- ->orWhere('width')->eq(3)
- ->markRight(1)
- ->andWhere('vision')->eq($block->vision)
- ->andWhere('hidden')->eq('0')
- ->andWhere('account')->eq($this->app->user->account)
- ->fetch('top');
- if(!$top) $top = 0;
- return (int)$top;
- }
- /**
- * 更新区块布局(保存每个区块的坐标信息)。
- * Update block layout.
- *
- * @param array $layout
- * @access public
- * @return bool
- */
- public function updateLayout($layout)
- {
- foreach($layout as $blockID => $block)
- {
- $this->dao->update(TABLE_BLOCK)->set('left')->eq($block['left'])->set('top')->eq($block['top'])->where('id')->eq($blockID)->exec();
- if(dao::isError()) return false;
- }
- return true;
- }
- /**
- * 获取项目列表存在的项目模式类型。
- * Get project model type from projectIdList.
- *
- * @param array $projectIdList
- * @access public
- * @return string all|scrum|waterfall
- */
- public function getModelType4Projects($projectIdList)
- {
- if(empty($projectIdList)) return '';
- $models = $this->dao->select('DISTINCT model')->from(TABLE_PROJECT)->where('id')->in($projectIdList)->fetchAll('model');
- $models = array_flip(array_keys($models));
- $haveScrum = (isset($models['scrum']) || isset($models['kanban']) || isset($models['agileplus']));
- $haveWater = (isset($models['waterfall']) || isset($models['waterfallplus']));
- if($haveScrum && $haveWater) return 'all';
- if($haveScrum) return 'scrum';
- if($haveWater) return 'waterfall';
- return '';
- }
- }
|