public function getModuleItems() { $basicModules = array('x2Activity', 'contacts', 'charts', 'accounts', 'opportunities', 'x2Leads', 'quotes', 'products', 'services', 'bugReports', 'users'); $qpg = new QueryParamGenerator(); $criteria = new CDbCriteria(); $criteria->condition = '(name in ' . $qpg->bindArray($basicModules, true) . ' or custom) and visible and moduleType in ("module", "pseudoModule") and name != "document"'; $criteria->params = $qpg->getParams(); $criteria->order = 'menuPosition ASC'; $modules = Modules::model()->findAll($criteria); $modules = array_filter($modules, function ($module) { if ($module->title === 'charts') { $action = 'ReportsChartDashboard'; } else { $action = ucfirst($module->title) . 'Index'; } $authItem = Yii::app()->authManager->getAuthItem($action); return Yii::app()->params->isAdmin || is_null($authItem) || Yii::app()->user->checkAccess($action); }); return array_map(function ($module) { $item = new ModulePanelItem(); $item->module = $module; return $item; }, $modules); }
public static function supportedModules(CDbCriteria $criteria = null) { $basicModules = array('x2Activity', 'topics', 'contacts', 'charts', 'accounts', 'opportunities', 'x2Leads', 'quotes', 'products', 'services', 'bugReports', 'users'); $qpg = new QueryParamGenerator(); $newCriteria = new CDbCriteria(); $newCriteria->condition = '(name in ' . $qpg->bindArray($basicModules, true) . ' or custom) and visible and moduleType in ("module", "pseudoModule") and name != "document"'; $newCriteria->params = $qpg->getParams(); $newCriteria->order = 'menuPosition ASC'; if ($criteria) { $newCriteria->mergeWith($criteria); $criteria = $newCriteria; } else { $criteria = $newCriteria; } $modules = Modules::model()->findAll($criteria); return $modules; }
/** * If this workflow is the default, unset isDefault flag on all other workflows */ public function afterSave() { if (in_array(self::DEFAULT_ALL_MODULES, $this->isDefaultFor)) { // this workflow is default for all modules, so remove all defaults Yii::app()->db->createCommand("\n update x2_modules\n set defaultWorkflow=NULL\n where true\n ")->execute(array(':id' => $this->id)); // remove old global default Yii::app()->db->createCommand("\n update x2_workflows\n set isDefault=0\n where id!=:id\n ")->execute(array(':id' => $this->id)); } else { // set default on a per-module basis // add new values if ($this->isDefaultFor) { $qpg = new QueryParamGenerator(); Yii::app()->db->createCommand("\n update x2_modules\n set defaultWorkflow=:id\n where id in " . $qpg->bindArray($this->isDefaultFor, true) . "\n ")->execute($qpg->mergeParams(array(':id' => $this->id))->getParams()); } // clear old values if ($this->isDefaultFor) { $qpg = new QueryParamGenerator(); Yii::app()->db->createCommand("\n update x2_modules\n set defaultWorkflow=NULL\n where id not in " . $qpg->bindArray($this->isDefaultFor, true) . " and\n defaultWorkflow=:id\n ")->execute($qpg->mergeParams(array(':id' => $this->id))->getParams()); } else { Yii::app()->db->createCommand("\n update x2_modules\n set defaultWorkflow=NULL\n where defaultWorkflow=:id\n ")->execute(array(':id' => $this->id)); } // if there's a global default, remove it Yii::app()->db->createCommand("\n update x2_workflows\n set isDefault=0\n where true\n ")->execute(); } parent::afterSave(); }
/** * Re-arrange the top bar menu. * * This form allows for the admin to change the order and visibility of top bar * menu items for all users. */ public function actionManageModules() { $modules = Modules::model()->findAll(); usort($modules, function ($a, $b) { $aPos = $a->menuPosition === null ? INF : (int) $a->menuPosition; $bPos = $b->menuPosition === null ? INF : (int) $b->menuPosition; if ($aPos < $bPos) { return -1; } elseif ($aPos > $bPos) { return 1; } else { return 0; } }); $selectedItems = array(); $deletableOptions = array(); $menuItems = array(); foreach ($modules as $module) { if ($module->name != 'users') { if (in_array($module->moduleType, array('link', 'recordLink'))) { $deletableOptions[] = $module->id; } $menuItems[$module->id] = $module->getTitle(); if ($module->visible) { $selectedItems[] = $module->id; } } } if (isset($_POST['formSubmit'])) { $selectedItems = isset($_POST['menuItems']) ? $_POST['menuItems'] : array(); $hiddenModuleIds = array_keys(array_diff_key($menuItems, array_flip($selectedItems))); // validate module ids $qpg = new QueryParamGenerator(); $count = (int) Yii::app()->db->createCommand("\n select count(*) from x2_modules\n where id in " . $qpg->bindArray(array_merge($selectedItems, $hiddenModuleIds), true))->queryScalar($qpg->getParams()); if ($count !== count(array_merge($selectedItems, $hiddenModuleIds))) { Yii::app()->user->setFlash('error', Yii::t('app', 'Selected module(s) not found.')); } elseif (Modules::updateTopBarLinks($selectedItems, $hiddenModuleIds)) { Yii::app()->user->setFlash('success', Yii::t('app', 'Updated top bar links.')); $this->redirect('manageModules'); } else { Yii::app()->user->setFlash('error', Yii::t('app', 'Failed to update top bar links.')); } } $this->render('manageModules', array('selectedItems' => $selectedItems, 'menuItems' => $menuItems, 'deletableOptions' => $deletableOptions)); }