예제 #1
0
 /**
  * Retrieves a list of model names.
  *
  * Obtains model names as an associative array with model names as the keys
  * and human-readable model names as their values. This is used in place of
  * {@link getDisplayedModelNamesList()} (formerly Admin::getModelList) where
  * specifying values for {@link modelName}, because the value of that should
  * ALWAYS be the name of the actual class, and {@link X2Model::getModelName()}
  * is guaranteed to return a class name (or false, if the class does not
  * exist).
  *
  * @param null|CDbCriteria $criteria if not null, will be used to query modules table. 
  *  Specifying a CDbCriteria will bypass caching.
  * @return array module titles indexed by associated model class names
  */
 public static function getModelNames($criteria = null)
 {
     if ($criteria !== null || !isset(self::$_modelNames)) {
         $modelNames = array();
         if ($criteria === null) {
             $modules = self::getModules();
         } else {
             $criteria->addColumnCondition(array('visible' => 1, 'editable' => true), 'AND', 'OR');
             $modules = X2Model::model('Modules')->findAll($criteria);
         }
         foreach ($modules as $module) {
             if ($modelName = X2Model::getModelName($module->name)) {
                 $modelNames[$modelName] = Yii::t('app', $module->title);
             } else {
                 // Shouldn't happen since getModelName uses class_exists
                 $modelNames[ucfirst($module->name)] = Yii::t('app', $module->title);
             }
         }
         asort($modelNames);
         if ($criteria !== null) {
             return $modelNames;
         } else {
             self::$_modelNames = $modelNames;
         }
     }
     return self::$_modelNames;
 }