* Copy buildMenu from framework into productModel class for refactoring.

This commit is contained in:
chentao
2023-06-26 14:03:08 +08:00
parent d93da43ef4
commit 583b5c80ed
+74
View File
@@ -1710,4 +1710,78 @@ class productModel extends model
return $item;
}
/**
* Build menu of a module.
*
* Copy of model class within framework/mode.class.php
*
* @param string $moduleName
* @param string $methodName
* @param string $params
* @param object $data
* @param string $type
* @param string $icon
* @param string $target
* @param string $class
* @param bool $onlyBody
* @param string $misc
* @param string $title
* @param bool $returnHtml
* @access public
* @return string
*/
public function buildMenu($moduleName, $methodName, $params, $data, $type = 'view', $icon = '', $target = '', $class = '', $onlyBody = false, $misc = '' , $title = '', $returnHtml = true)
{
if(str_contains($moduleName, '.')) [$appName, $moduleName] = explode('.', $moduleName);
if(str_contains($methodName, '_') && strpos($methodName, '_') > 0) [$module, $method] = explode('_', $methodName);
if(empty($module)) $module = $moduleName;
if(empty($method)) $method = $methodName;
static $actions = array();
if($this->config->edition != 'open')
{
if(empty($actions[$moduleName]))
{
$actions[$moduleName] = $this->dao->select('*')->from(TABLE_WORKFLOWACTION)
->where('module')->eq($moduleName)
->andWhere('buildin')->eq('1')
->andWhere('status')->eq('enable')
->beginIF(!empty($this->config->vision))->andWhere('vision')->eq($this->config->vision)->fi()
->fetchAll('action');
}
}
$enabled = true;
if(!empty($actions) and isset($actions[$moduleName][$methodName]))
{
$action = $actions[$moduleName][$methodName];
if($action->extensionType == 'override') return $this->loadModel('flow')->buildActionMenu($moduleName, $action, $data, $type);
$conditions = json_decode((string) $action->conditions);
if($conditions and $action->extensionType == 'extend')
{
if($icon != 'copy' and $methodName != 'create') $title = $action->name;
if($conditions) $enabled = $this->loadModel('flow')->checkConditions($conditions, $data);
}
else
{
if(method_exists($this, 'isClickable')) $enabled = $this->isClickable($data, $method, $module);
}
}
else
{
if(method_exists($this, 'isClickable')) $enabled = $this->isClickable($data, $method, $module);
}
if(!$returnHtml) return $enabled;
$html = '';
$type = $type == 'browse' ? 'list' : 'button';
$html = common::buildIconButton($module, $method, $params, $data, $type, $icon, $target, $class, $onlyBody, $misc, $title, '', $enabled);
return $html;
}
}