Files
OMS/app/desktop/lib/application/menu.php
2026-01-04 19:08:31 +08:00

158 lines
6.5 KiB
PHP

<?php
/**
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class desktop_application_menu extends desktop_application_prototype_xml
{
public $xml = 'desktop.xml';
public $xsd = 'desktop_content';
public $path = 'workground';
/**
* current
* @return mixed 返回值
*/
public function current()
{
$this->current = $this->iterator()->current();
$this->current['action'] = $this->current['action'] ? $this->current['action'] : 'index';
$this->key = $this->target_app->app_id . '_ctl_' . $this->current['controller'];
return $this;
}
/**
* row
* @param mixed $fag fag
* @param mixed $key key
* @return mixed 返回值
*/
public function row($fag, $key)
{
if ($this->current['menugroup'][$fag]['menu'][$key]['params']) {
$a_tmp = explode('|', $this->current['menugroup'][$fag]['menu'][$key]['params']);
foreach ((array) $a_tmp as $k => $v) {
$a = explode(':', $v);
if (strpos($a[0], 'p[') !== false) {
$a = explode(':', $v);
eval('$url_params' . str_replace('p', '["p"]', $a[0]) . ' = $a[1];');
} else {
$url_params[$a[0]] = $a[1];
}
}
$addon['url_params'] = $url_params;
unset($url_params);
}
$row = array(
'menu_type' => $this->content_typename(),
'app_id' => $this->target_app->app_id,
'workground' => $this->current['id'],
'content_name' => $this->key(),
'menu_group' => $this->current['menugroup'][$fag]['name'],
'menu_order' => $this->current['menugroup'][$fag]['menu'][$key]['order'],
'addon' => serialize($addon),
'target' => $this->current['menugroup'][$fag]['menu'][$key]['target'] ? $this->current['menugroup'][$fag]['menu'][$key]['target'] : '',
'en' => $this->current['menugroup'][$fag]['en'],
);
$this->current['menugroup'][$fag]['menu'][$key]['action'] = $this->current['menugroup'][$fag]['menu'][$key]['action'] ? $this->current['menugroup'][$fag]['menu'][$key]['action'] : 'index';
$row['menu_path'] = "app={$this->target_app->app_id}&ctl={$this->current['menugroup'][$fag]['menu'][$key]['controller']}&act={$this->current['menugroup'][$fag]['menu'][$key]['action']}";
$row['menu_title'] = $this->current['menugroup'][$fag]['menu'][$key]['value'];
$row['permission'] = $this->current['menugroup'][$fag]['menu'][$key]['permission'];
$row['display'] = $this->current['menugroup'][$fag]['menu'][$key]['display'] ? $this->current['menugroup'][$fag]['menu'][$key]['display'] : "true";
return $row;
}
/**
* menu_row
* @param mixed $fag fag
* @return mixed 返回值
*/
public function menu_row($fag)
{
if ($this->current['menu'][$fag]['params']) {
$a_tmp = explode('|', $this->current['menu'][$fag]['params']);
foreach ((array) $a_tmp as $k => $v) {
$a = explode(':', $v);
$url_params[$a[0]] = $a[1];
}
$addon['url_params'] = $url_params;
unset($url_params);
}
$row = array(
'menu_type' => $this->content_typename(),
'app_id' => $this->target_app->app_id,
'workground' => $this->current['id'],
'content_name' => $this->key(),
'menu_group' => '',
'menu_order' => $this->current['menu'][$fag]['order'],
'addon' => serialize($addon),
'target' => $this->current['menu'][$fag]['target'] ? $this->current['menu'][$fag]['target'] : '',
);
# $row = parent::row();
$this->current['menu'][$fag]['action'] = $this->current['menu'][$fag]['action'] ? $this->current['menu'][$fag]['action'] : 'index';
$row['menu_path'] = "app={$this->target_app->app_id}&ctl={$this->current['menu'][$fag]['controller']}&act={$this->current['menu'][$fag]['action']}";
$row['menu_title'] = $this->current['menu'][$fag]['value'];
$row['permission'] = $this->current['menu'][$fag]['permission'];
$row['display'] = $this->current['menu'][$fag]['display'];
return $row;
}
/**
* install
* @return mixed 返回值
*/
public function install()
{
foreach ((array)$this->current['menugroup'] as $fag => $val) {
foreach ((array)$val['menu'] as $key => $data) {
kernel::log('Installing ' . $this->content_typename() . ' ' . $this->key() . $data['controller'] . '::' . $data['action']);
$menus_row = $this->row($fag, $key);
app::get('desktop')->model('menus')->insert($menus_row);
}
}
if ($this->current['menu']) {
foreach ($this->current['menu'] as $fag => $val) {
kernel::log('Installing ' . $this->content_typename() . ' ' . $this->key() . $data['controller'] . '::' . $data['action']);
$menu_row = $this->menu_row($fag);
app::get('desktop')->model('menus')->insert($menu_row);
}
}
if ($menus_row) {
base_kvstore::instance('menudefine')->store('version', date('YmdHis'));
}
}
/**
* 清除_by_app
* @param mixed $app_id ID
* @return mixed 返回值
*/
public function clear_by_app($app_id)
{
if (!$app_id) {
return false;
}
app::get('desktop')->model('menus')->delete(array(
'app_id' => $app_id, 'menu_type' => $this->content_typename()));
}
}