function getCatalogInfo() { // $fileName = $this->getPath().$this->_props['name'].'.'.Q::ini('appini/catalog/fileInfoExt', 'inf'); // //读取文件编目信息 // $handle = @fopen($fileName, 'a+'); // if($handle){ // $filesize = @filesize($fileName); // if ($filesize > 0){ // $json = @fread ($handle, $filesize); // $catalogInfo = Helper_JSON::decode($json); // }else{ // $catalogInfo = array(); // } // @fclose ($handle); // } $catalogInfo = $this->_props['catalog_info'] == null ? array() : Helper_JSON::decode($this->_props['catalog_info']); //获得编目信息分类 $catalog = Catalog::find('path like ? and enabled=1', '%,' . ($this->_props['type'] + 1) . ',%')->order('weight desc')->asArray()->getAll(); $catalog = Helper_Array::toTree($catalog, 'id', 'parent_id', 'children'); //合并编目信息 foreach ($catalog as $k => $v) { if (isset($catalogInfo[$v['name']])) { foreach ($v['children'] as $_k => $_v) { if (!isset($catalogInfo[$v['name']][$_v['name']])) { $catalogInfo[$v['name']][$_v['name']] = ''; } } } else { foreach ($v['children'] as $_k => $_v) { $catalogInfo[$v['name']][$_v['name']] = ''; } } } return $catalogInfo; }
function render() { //得到属性的值 $id = $this->_extract('id', 'parent_id'); $value = $this->_extract('value'); $out = null; //得到所有的类别 $teaType = TeaType::find()->asArray()->getAll(); //转换成item=>name数据 $teaTree = Helper_Array::toTree($teaType, 'id', 'parent_id'); $teaTree = TeaType::treeToArray($teaTree); //生成有落差下拉类表的html $out .= "<select id=\"{$id}\" name=\"{$id}\" >"; $out .= "<option value=\"-1\" >请选择类别</option>"; foreach ($teaTree as $option) { $out .= "<option value=\"{$option['id']}\" "; //是否该分类 是父分类 if ($option['id'] == $value) { $out .= "selected=\"selected\""; } $out .= ">"; for ($i = 0; $i < $option['level']; $i++) { $out .= " "; } $out .= $option['name']; $out .= "</option>"; } $out .= "</select>"; return $out; }
public function index() { $oBus = Business_App_Rol::listRol('', NULL, NULL); $eRols = $oBus->getInData('eRols'); $combo_rol = Helper_Array::entitiesToIdText($eRols, 'id', 'name', 'value', 'text'); Helper_App_View::layout('app/html/pages/security_profile/page', array('combo_rol' => $combo_rol)); }
public static function listByType($catalog_type_mix) { $oBus = new Response_Business(); $MY =& MY_Controller::get_instance(); /* @var $mCatalog Catalog_Model */ $mCatalog =& $MY->mCatalog; $data = array(); try { if (is_array($catalog_type_mix)) { foreach ($catalog_type_mix as $idx => $value) { $eCatalogos = $mCatalog->listByType($value); $eCatalogos = Helper_Array::entitiesToIdText($eCatalogos, 'code', 'name', 'value', 'text'); $data[$value] = $eCatalogos; } } else { $eCatalogos = $mCatalog->listByType($catalog_type_mix); $eCatalogos = Helper_Array::entitiesToIdText($eCatalogos, 'code', 'name', 'value', 'text'); $data[$catalog_type_mix] = $eCatalogos; } $oBus->isSuccess(TRUE); } catch (Exception $e) { $oBus->isSuccess(FALSE); $oBus->message($e->getMessage()); } $oBus->data(array('eCatalogs' => $data)); return $oBus; }
static function getArrayTree() { $category = Category::find('enabled=1')->asArray()->getAll(); $category = Helper_Array::toTree($category, 'id', 'parent_id', 'childrens'); $category = Helper_ArrayTree::dumpArrayTree($category, -1); return $category; }
/** * 添加新闻类别的属性 * */ function getSorts() { $sort = Articlesorts::find('parent_id =1')->setColumns('id,name')->asArray()->getAll(); $arr = array('id' => 0, 'name' => '请选择类别'); array_unshift($sort, $arr); $sort = Helper_Array::toHashmap($sort, 'id', 'name'); return $sort; }
/** * 茶叶类别列表 * * @return array */ function getTypeList() { $sort = $this->find()->setColumns('id,name')->asArray()->getAll(); $arr = array('id' => 0, 'name' => '请选择类别'); array_unshift($sort, $arr); $sort = Helper_Array::toHashmap($sort, 'id', 'name'); return $sort; }
/** * 茶叶栏目列表 * */ function actionIndex() { // 为 $this->_view 指定的值将会传递数据到视图中 # $this->_view['text'] = 'Hello!'; $tea_type = TeaType::find()->asArray()->getAll(); //转换成分类的树 $tea_tree = Helper_Array::toTree($tea_type, 'id', 'parent_id', 'nodes'); $tea_tree = TeaType::treeToArray($tea_tree, 'nodes'); $this->_view['teatypes'] = $tea_tree; }
function render() { //得到属性的值 $name = $this->_extract('name'); $catch_id = 'Dy_menu' . $name; //读取缓存 $rowSet = Q::cache($catch_id); //读取失败 if (!$rowSet) { $rowSet = Sysmenu::find()->order('parent_id ASC, order_pos ASC')->asArray()->getAll(); //写缓存 Q::writeCache($catch_id, $rowSet); } /** * 验证不能访问的菜单 */ $app = MyApp::instance(); foreach ($rowSet as $offset => $row) { if ($row['controller'] == '') { continue; } $udi = "{$row['controller']}/{$row['action']}"; //权限判断 if (!$app->authorizedUDI($app->currentUserRoles(), $udi)) { //删除没有权限访问的菜单 unset($rowSet[$offset]); } else { $args = array(); parse_str($row['args'], $args); $rowSet[$offset]['url'] = url($udi, $args); } } //数组转换成树 $menu = Helper_Array::toTree($rowSet, 'menu_id', 'parent_id', 'submenu'); // $mainMenu = & new Helper_Menu($menu) ; $mainMenu = new Helper_Menu($menu); $output = "var {$name} = "; $output .= $mainMenu->returnJsArray(true); $output .= ";\n"; echo <<<EOT <div id="mainMenuBar"></div> <link href="js/ThemeOffice/theme.css" rel="stylesheet" type="text/css" /> <script language="javascript" type="text/javascript" src="js/JSCookMenu.js"></script> <script language="javascript" type="text/javascript" src="js/ThemeOffice/theme.js"></script> <script language="javascript" type="text/javascript"> {{$output}} cmDraw ('mainMenuBar', myMenu, 'hbr', cmThemeOffice); </script> EOT; }
/** * 从配置文件中生成新闻表单 * * @param string $action 表单的url * @param string $config 配置文件的名字 * @return object 表单对象 */ static function _createFormConfig($action, $config) { $form = new Form_Admin_News('create_news', $action); $fileName = dirname(__FILE__) . DS . "{$config}"; $form->loadFromConfig(Helper_YAML::load($fileName)); $form->addValidations(News::meta()); //查询类别 $sort = NewSort::find()->order('name ASC')->getAll(); $sort = Helper_Array::toHashmap($sort, 'id', 'name'); $form['newbody']['sort_id']->items = $sort; return $form; }
public static function parse($pathInfo) { $routerConfig = Core_Config::load('Router'); if (NULL == $pathInfo) { $pathInfo = self::getPathInfo(); } $pathInfos = $pathInfo ? explode('/', trim($pathInfo, '/')) : array(); if (!$pathInfos) { return $routerConfig["DefaultDispatchInfo"]; } $controller = array_shift($pathInfos); $controller = $controller ? ucfirst($controller) : $routerConfig["DefaultDispatchInfo"]["controller"]; $action = array_shift($pathInfos); $action = $action ? $action : $routerConfig["DefaultDispatchInfo"]["action"]; // 解析GET参数,例如: // _directory/controller/action/k1/v1/k2/v2 // 从 action 后的 key1 开始为 k/v 组合参数串 // *因为前面已经两次 array_shift 弹出数组头元素 // 所以此时的 $pathInfos 数组值已经是: array(k1, v1, k2, v2),那么再转为关联数组即可 array(k1 => v1, k2 => v2) $params = $pathInfos ? Helper_Array::assoc($pathInfos) : array(); // 解析pathinfo风格URL return array('controller' => $controller, 'action' => $action, 'params' => $params); }
/** * 返回结构 * array( * 'ds_id' => array('tags' => '', 'unit' => '', ...) * ... * ) * * */ public static function getDataStreamsByDeviceData($device_data) { if (empty($device_data['datastreams'])) { return array(); } $datastreams = $device_data['datastreams']; return Helper_Array::changeKey($datastreams, 'id'); }
static function layout($view, $arrParams = array(), $arrParamsLayout = array(), $useIframe = FALSE) { $MY =& MY_Controller::get_instance(); /* @var $mConfigurationSystem Configuration_System_Model */ $mConfigurationSystem =& $MY->mConfigurationSystem; /* @var $mCompany Company_Model */ $mCompany =& $MY->mCompany; /* @var $mCompanyBranch Company_Branch_Model */ $mCompanyBranch =& $MY->mCompanyBranch; /* @var $mProfile profile_Model */ $mProfile =& $MY->mProfile; /* @var $mUser User_Model */ $mUser =& $MY->mUser; /* @var $mPerson Person_Model */ $mPerson =& $MY->mPerson; /* @var $mUserProfile User_Profile_Model*/ $mUserProfile =& $MY->mUserProfile; /* @var $mUserProfileCompanyBranch User_Profile_Company_Branch_Model */ $mUserProfileCompanyBranch =& $MY->mUserProfileCompanyBranch; /* @var $mAppVersion App_Version_Model */ $mAppVersion =& $MY->mAppVersion; $id_system = Helper_Config::getSystemId(); $id_company = Helper_App_Session::getCompanyId(); $id_company_branch = Helper_App_Session::getCompanyBranchId(); $id_profile = Helper_App_Session::getProfileId(); $id_user = Helper_App_Session::getUserId(); /* @var $eConfigurationSystem eConfigurationSystem */ $eConfigurationSystem = $mConfigurationSystem->load($id_system); /* @var $eCompany eCompany */ $eCompany = $mCompany->load($id_company); /* @var $eProfile eProfile */ $eProfile = $mProfile->load($id_profile); /* @var $eUser eUser */ $eUser = $mUser->load($id_user); /* @var $ePerson ePerson */ $ePerson = $mPerson->load($eUser->id_person); /* @var $eAppVersion eAppVersion */ $eAppVersion = $mAppVersion->loadArray(array('isActive' => 1, 'isProject' => 1)); $resources_path = 'resources/assets/app'; $arrMenu = Helper_App_Permission::getMenu(); $controller_current = $MY->uri->rsegment(1); $function_current = $MY->uri->rsegment(2); // ================================================================ // ================================================================ $eProfiles = $mUserProfile->listProfilesByUser($id_user, 1); $show_combo_perfiles = TRUE; $combo_perfiles = Helper_Array::entitiesToIdText($eProfiles, 'id', 'name', 'value', 'text', $id_profile); // ================================================================ // ================================================================ if (empty($eProfiles)) { $flash = new Response_Flash(); $flash->message('Ningun Perfil disponible!'); $flash->flashType(Response_Flash::FLASH_ERROR); Helper_App_Flash::set($flash); $show_combo_perfiles = FALSE; $useIframe = TRUE; $view = 'app/html/error/403'; } // ================================================================ // ================================================================ $eCompanyBranches = Helper_App_Session::isSuperAdminProfile() || Helper_App_Session::isAdminProfile() ? $mCompanyBranch->listByCompany($id_company) : $mUserProfileCompanyBranch->listCompanyBranchsByUserProfile($id_user, $id_profile); $show_combo_sedes = TRUE; $combo_sedes = Helper_Array::entitiesToIdText($eCompanyBranches, 'id', 'name', 'value', 'text', $id_company_branch); if (empty($eCompanyBranches)) { $flash = new Response_Flash(); $flash->message('Ninguna Sucursal disponible!'); $flash->flashType(Response_Flash::FLASH_ERROR); Helper_App_Flash::set($flash); $show_combo_sedes = FALSE; $useIframe = TRUE; $view = 'app/html/error/403'; } $content = ''; if (is_array($view)) { foreach ($view as $v) { $content .= $MY->load->view($v, $arrParams, true); } } else { $content = $MY->load->view($view, $arrParams, true); } $browser = Helper_App_Session::isIExplorer(); $arrParamsLayoutDefault = array('useIframe' => $useIframe, 'resources_path' => $resources_path, 'content' => $content, 'arrMenu' => $arrMenu, 'controller_current' => $controller_current, 'function_current' => $function_current, 'navegador' => $browser, 'eConfigurationSystem' => $eConfigurationSystem, 'eCompany' => $eCompany, 'eProfile' => $eProfile, 'ePerson' => $ePerson, 'eUser' => $eUser, 'eAppVersion' => $eAppVersion, 'show_combo_perfiles' => $show_combo_perfiles, 'combo_perfiles' => $combo_perfiles, 'show_combo_sedes' => $show_combo_sedes, 'combo_sedes' => $combo_sedes); $MY->load->view('app/html/layout/layout', array_merge($arrParamsLayoutDefault, $arrParamsLayout)); }
/** * 有些Model查询出来数组数据包含一些ID * 该方法指定字段,并指定查询字段,指定Model,自动进行统一查询 * */ public static function getModelExtDatas($ori_data, $data_field, $select_field, $model, $where = array()) { if (empty($ori_data)) { return array(); } $data_field_ids = Helper_Array::getColumn($ori_data, $data_field); if (empty($data_field_ids)) { return array(); } $data_field_ids = array_unique($data_field_ids); $datas = $model->selectByField($select_field, $data_field_ids); if (empty($datas)) { $datas = array(); } return $datas; }
private function loadCiudad() { $resAjax = new Response_Ajax(); $id_provincia = $this->input->post('id_provincia'); try { $oBus = Business_App_Ciudad::listCiudad($id_provincia, $eCiudades); if (!$oBus->isSuccess()) { throw new Exception($oBus->message()); } $combo_ciudad = Helper_Array::entitiesToIdText($eCiudades, 'id', 'nombre', 'value', 'text'); $resAjax->isSuccess(TRUE); } catch (Exception $e) { $resAjax->isSuccess(FALSE); $resAjax->message($e->getMessage()); } $resAjax->data(array('cbo-ciudad' => $combo_ciudad)); echo $resAjax->toJsonEncode(); }
private function loadComponentsModalModule() { $resAjax = new Response_Ajax(); $id_company = Helper_App_Session::getCompanyId(); $combo_modules = array(array('id' => 0, 'name' => '<< --MÓDULO PADRE-- >>')); try { $oBus = Business_App_Module::listModules(NULL); if (!$oBus->isSuccess()) { throw new Exception($oBus->message()); } $data = $oBus->data(); $eModules = $data['eModules']; $combo_modules2 = Helper_Array::entitiesToIdText($eModules, 'id', 'name', 'id', 'name'); $combo_modules = array_merge($combo_modules, $combo_modules2); $resAjax->isSuccess(TRUE); } catch (Exception $e) { $resAjax->isSuccess(FALSE); $resAjax->message($e->getMessage()); } $resAjax->data(array('combo-modules' => $combo_modules)); echo $resAjax->toJsonEncode(); }
public static function resortByOtherArr($arr, $other_arr, $field = 'id') { $arr = Helper_Array::changeKey($arr, $field); $ret = array(); foreach ($other_arr as $field_data) { if (isset($arr[$field_data])) { $ret[$field_data] = $arr[$field_data]; } else { continue; } } return $ret; }
private function loadComponentsModalRol() { $resAjax = new Response_Ajax(); $combo_rol = array(array('value' => 0, 'text' => '<< --ROLES-- >>')); try { $oBus = Business_App_Rol::listRol('', NULL, NULL); if (!$oBus->isSuccess()) { throw new Exception($oBus->message()); } $eRols = $oBus->getInData('eRols'); $combo_rol2 = Helper_Array::entitiesToIdText($eRols, 'id', 'name', 'value', 'text'); $combo_roles = array_merge($combo_rol, $combo_rol2); $resAjax->isSuccess(TRUE); } catch (Exception $e) { $resAjax->isSuccess(FALSE); $resAjax->message($e->getMessage()); } $resAjax->data(array('combo-roles' => $combo_roles)); echo $resAjax->toJsonEncode(); }
/** * 递归合并两个或多个数组 * 本函数内使用for语句,以及func_get_arg函数,实现多个数组递归合并 * $john = array('name' => 'john', 'children' => array('fred', 'paul', 'sally', 'jane')); * $mary = array('name' => 'mary', 'children' => array('jane')); * * $john = Helper_Array::merge($john, $mary); * * array('name' => 'mary', 'children' => array('fred', 'paul', 'sally', 'jane')) * * @param a1 原始数组 * @param a2 需要合并的数组 * @return array */ public static function merge(array $a1, array $a2) { $result = array(); for ($i = 0, $total = func_num_args(); $i < $total; $i++) { $arr = func_get_arg($i); $assoc = Helper_Array::isAssoc($arr); foreach ($arr as $key => $val) { if (isset($result[$key])) { if (is_array($val) && is_array($result[$key])) { if (Helper_Array::isAssoc($val)) { $result[$key] = Helper_Array::merge($result[$key], $val); } else { $diff = array_diff($val, $result[$key]); $result[$key] = array_merge($result[$key], $diff); } } else { if ($assoc) { $result[$key] = $val; } elseif (!in_array($val, $result, true)) { $result[] = $val; } } } else { $result[$key] = $val; } } } return $result; }
function parse($path, array $var = array(), $maxDepth = null) { $file = $this->basePath . '/' . ltrim($path, '/'); $meta = array(); foreach (array(dirname(dirname($file)), dirname($file)) as $v) { $v .= '/_meta.txt'; if (file_exists($v)) { $meta = array_merge_recursive($meta, $this->parseArr($this->getContent($v), $maxDepth)); } } $content = $this->getContent($file); // parse here doc $hereDoc = array(); $content = preg_replace_callback('/<<<(.+)>>>/sm', function (&$node) use(&$hereDoc) { $hereDoc[] = $node[1]; return '\\d' . (count($hereDoc) - 1); }, $content); $arr = $this->parseArr($content, $maxDepth); if (array_key_exists('_meta', $arr)) { if (!empty($arr['_meta'])) { $meta = array_merge_recursive($meta, $arr['_meta']); } unset($arr['_meta']); } if (!empty($meta['_unset'])) { Helper_Array::unsetr($meta, $meta['_unset']); unset($meta['_unset']); } foreach ($arr as $k => $v) { if (null == $v) { unset($arr[$k]); continue; } $parent = $meta; // unset if (!empty($v['_unset'])) { Helper_Array::unsetr($parent, $v['_unset']); unset($v['_unset']); } // default if (!empty($parent['default'])) { list($v, $temp) = array($parent['default'], $v); Helper_Array::merger($v, $temp); } // replace Helper_Array::pregReplacer('/^\\\\k$/', $k, $v); // key clean Helper_Array::pregKeyReplacer('/^\\\\s(\\d+)$/', '\\1', $v); // prefix if (!empty($parent['prefix'])) { Helper_Array::prefixr($v, $parent['prefix']); } // suffix if (!empty($parent['suffix'])) { Helper_Array::suffixr($v, $parent['suffix']); } // wraper if (!empty($parent['wraper'])) { Helper_Array::wraperr($v, $parent['wraper']); } // var replace if (!empty($var)) { array_walk_recursive($v, function (&$v, $k, $var) { if (is_string($v)) { preg_match_all('/\\{\\$(\\w+)\\}/', $v, $matches); if (!empty($matches[1])) { foreach ($matches[1] as $v1) { if (isset($var[$v1])) { $v = str_replace('{$' . $v1 . '}', $var[$v1], $v); } } } } }, $var); } // \d 恢复 $search = $replace = array(); for ($i = 0; $i < count($hereDoc); $i++) { $search[] = '/^\\\\d' . $i . '$/'; $replace[] = $hereDoc[$i]; } Helper_Array::pregReplacer($search, $replace, $v); $arr[$k] = $v; } // \h自继承 $funcH = function (array &$subject) use(&$funcH, $arr) { foreach ($subject as $k => &$v) { if ('\\h' === $k) { $key = explode(' ', $v); $value = Helper_Array::current($arr, $key); $key = array_pop($key); $subject[$key] = $value; unset($subject[$k]); } elseif (is_array($v)) { call_user_func_array($funcH, array(&$v)); } } }; $funcH($arr); // \i 包含 $dir = dirname($file) . '/_inc'; Helper_Array::pregReplaceCallbackr('/\\\\i(.+)/', function ($node) use($dir) { $file = $dir . '/' . trim($node[1]); if (file_exists($file)) { return file_get_contents($file); } }, $arr); return $arr; }
public function index() { $array_array = array(array('id' => Helper_App_Log::LOG_DEFAULT, 'name' => 'DEFAULT'), array('id' => Helper_App_Log::LOG_LOGIN, 'name' => 'DEBUG'), array('id' => Helper_App_Log::LOG_INSERT, 'name' => 'INSERT'), array('id' => Helper_App_Log::LOG_UPDATE, 'name' => 'UPDATE'), array('id' => Helper_App_Log::LOG_DELETE, 'name' => 'DELETE')); $combo_action = Helper_Array::toIdText($array_array, 'id', 'name'); Helper_App_View::layout('app/html/pages/security_binnacle/page', array('combo_action' => $combo_action)); }
protected function _clearCacheByCondtion($where) { if (isset($where[$this->_primary_id])) { $this->_clearItemCache($where[$this->_primary_id]); return; } //查询出id,清空缓存 $items = $this->select($where, array('select' => $this->_primary_id)); if (empty($items)) { return; } $ids = Helper_Array::getColumn($items, $this->_primary_id); $this->_clearItemCache($ids); }