* code for block.
This commit is contained in:
+262
-16
@@ -11,26 +11,203 @@
|
||||
*/
|
||||
class blockModel extends model
|
||||
{
|
||||
/**
|
||||
* Save params
|
||||
*
|
||||
* @param int $index
|
||||
* @param string $type
|
||||
* @param string $appName
|
||||
* @param int $blockID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function save($index, $source, $module = 'my', $blockID = 0)
|
||||
{
|
||||
$data = fixer::input('post')
|
||||
->add('account', $this->app->user->account)
|
||||
->add('order', $index)
|
||||
->add('module', $module)
|
||||
->add('hidden', 0)
|
||||
->setIF($blockID, 'id', $blockID)
|
||||
->setDefault('grid', '4')
|
||||
->setDefault('source', $source)
|
||||
->setDefault('params', array())
|
||||
->get();
|
||||
|
||||
$data->params = helper::jsonEncode($data->params);
|
||||
$this->dao->replace(TABLE_BLOCK)->data($data)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block by ID.
|
||||
*
|
||||
* @param int $blockID
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getByID($blockID)
|
||||
{
|
||||
$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();
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get saved block config.
|
||||
*
|
||||
* @param int $index
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getBlock($index, $module = 'my')
|
||||
{
|
||||
$block = $this->dao->select('*')->from(TABLE_BLOCK)
|
||||
->where('`order`')->eq($index)
|
||||
->andWhere('account')->eq($this->app->user->account)
|
||||
->andWhere('module')->eq($module)
|
||||
->fetch();
|
||||
if(empty($block)) return false;
|
||||
|
||||
$block->params = json_decode($block->params);
|
||||
if(empty($block->params)) $block->params = new stdclass();
|
||||
return $block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get last key.
|
||||
*
|
||||
* @param string $appName
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function getLastKey($module = 'my')
|
||||
{
|
||||
$index = $this->dao->select('`order`')->from(TABLE_BLOCK)
|
||||
->where('module')->eq($module)
|
||||
->andWhere('account')->eq($this->app->user->account)
|
||||
->orderBy('order desc')
|
||||
->limit(1)
|
||||
->fetch('order');
|
||||
return $index ? $index : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block list for account.
|
||||
*
|
||||
* @param string $appName
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getBlockList($module = 'my')
|
||||
{
|
||||
$blocks = $this->dao->select('*')->from(TABLE_BLOCK)->where('account')->eq($this->app->user->account)
|
||||
->andWhere('module')->eq($module)
|
||||
->andWhere('hidden')->eq(0)
|
||||
->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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hidden blocks
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getHiddenBlocks($module = 'my')
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_BLOCK)->where('account')->eq($this->app->user->account)
|
||||
->andWhere('module')->eq($module)
|
||||
->andWhere('hidden')->eq(1)
|
||||
->orderBy('`order`')
|
||||
->fetchAll('order');
|
||||
}
|
||||
|
||||
/**
|
||||
* Init block when account use first.
|
||||
*
|
||||
* @param string $appName
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function initBlock($module)
|
||||
{
|
||||
$blocks = $this->lang->block->default[$module];
|
||||
$account = $this->app->user->account;
|
||||
|
||||
/* Mark this app has init. */
|
||||
$this->loadModel('setting')->setItem("$account.$module.common.blockInited", true);
|
||||
foreach($blocks as $index => $block)
|
||||
{
|
||||
$block['order'] = $index;
|
||||
$block['module'] = $module;
|
||||
$block['account'] = $account;
|
||||
$block['params'] = isset($block['params']) ? helper::jsonEncode($block['params']) : '';
|
||||
if(!isset($block['source'])) $block['source'] = $module;
|
||||
|
||||
$this->dao->replace(TABLE_BLOCK)->data($block)->exec();
|
||||
}
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get block list.
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getAvailableBlocks()
|
||||
public function getAvailableBlocks($module = '')
|
||||
{
|
||||
if($module and isset($this->lang->block->modules[$module]))return json_encode($this->lang->block->modules[$module]->availableBlocks);
|
||||
return json_encode($this->lang->block->availableBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list params for product|project|todo
|
||||
*
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getListParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
|
||||
if($module == 'project' or $module == 'product')
|
||||
{
|
||||
$params->type['name'] = $this->lang->block->type;
|
||||
$params->type['options'] = $this->lang->block->typeList->$module;
|
||||
$params->type['control'] = 'select';
|
||||
}
|
||||
|
||||
$params = $this->onlyNumParams($module, $params);
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get todo params.
|
||||
*
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getTodoParams()
|
||||
public function getTodoParams($module = '')
|
||||
{
|
||||
return $this->getProductParams();
|
||||
return $this->getListParams($module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +216,7 @@ class blockModel extends model
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getTaskParams()
|
||||
public function getTaskParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
$params->type['name'] = $this->lang->block->type;
|
||||
@@ -64,7 +241,7 @@ class blockModel extends model
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getBugParams()
|
||||
public function getBugParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
$params->type['name'] = $this->lang->block->type;
|
||||
@@ -89,7 +266,7 @@ class blockModel extends model
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getCaseParams()
|
||||
public function getCaseParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
$params->type['name'] = $this->lang->block->type;
|
||||
@@ -108,13 +285,34 @@ class blockModel extends model
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get testtask params.
|
||||
*
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getTesttaskParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
$params->type['name'] = $this->lang->block->type;
|
||||
$params->type['options'] = $this->lang->block->typeList->testtask;
|
||||
$params->type['control'] = 'select';
|
||||
|
||||
$params->num['name'] = $this->lang->block->num;
|
||||
$params->num['default'] = 20;
|
||||
$params->num['control'] = 'input';
|
||||
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get story params.
|
||||
*
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getStoryParams()
|
||||
public function getStoryParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
$params->type['name'] = $this->lang->block->type;
|
||||
@@ -133,20 +331,51 @@ class blockModel extends model
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plan params.
|
||||
*
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getPlanParams($module = '')
|
||||
{
|
||||
$params = $this->onlyNumParams($module);
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Release params.
|
||||
*
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getReleaseParams($module = '')
|
||||
{
|
||||
$params = $this->onlyNumParams($module);
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Build params.
|
||||
*
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getBuildParams($module = '')
|
||||
{
|
||||
$params = $this->onlyNumParams($module);
|
||||
return json_encode($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product params.
|
||||
*
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getProductParams()
|
||||
public function getProductParams($module = '')
|
||||
{
|
||||
$params = new stdclass();
|
||||
$params->num['name'] = $this->lang->block->num;
|
||||
$params->num['default'] = 20;
|
||||
$params->num['control'] = 'input';
|
||||
|
||||
return json_encode($params);
|
||||
return $this->getListParams($module);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,8 +384,25 @@ class blockModel extends model
|
||||
* @access public
|
||||
* @return json
|
||||
*/
|
||||
public function getProjectParams()
|
||||
public function getProjectParams($module = '')
|
||||
{
|
||||
return $this->getProductParams();
|
||||
return $this->getListParams($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build number params.
|
||||
*
|
||||
* @param string $module
|
||||
* @param object $params
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function onlyNumParams($module = '', $params = '')
|
||||
{
|
||||
if(empty($params)) $params = new stdclass();
|
||||
$params->num['name'] = $this->lang->block->num;
|
||||
$params->num['default'] = 20;
|
||||
$params->num['control'] = 'input';
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user