예제 #1
0
 /**
  *    List models
  *
  * @param Charcoal_Sandbox $sandbox
  * @param int $find_path
  *
  * @return Charcoal_ITableModel[]
  */
 public function listModels($sandbox, $find_path)
 {
     // get root path of framework,project,web_app
     $dir_framework = Charcoal_ResourceLocator::getFrameworkPath();
     $dir_project = Charcoal_ResourceLocator::getProjectPath();
     $dir_application = Charcoal_ResourceLocator::getApplicationPath();
     // get module root path of framework,project,web_app
     $dir_framework_module = $dir_framework . '/module';
     $dir_project_module = $dir_project . '/module';
     $dir_application_module = $dir_application . '/module';
     $config_target_list = array();
     if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_FRAMEWORK)) {
         $config_target_list[] = $dir_framework . '/config/table_model';
         $config_target_list[] = $dir_framework_module . '/config/table_model';
     }
     if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_PROJECT)) {
         $config_target_list[] = $dir_project . '/config/table_model';
         $config_target_list[] = $dir_project_module . '/config/table_model';
     }
     if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_APPLICATION)) {
         $config_target_list[] = $dir_application . '/config/table_model';
         $config_target_list[] = $dir_application_module . '/config/table_model';
     }
     // find model names in target directory
     $table_model_names = array();
     foreach ($config_target_list as $path) {
         $found_models = $sandbox->getRegistry()->listObjects($path, 'table_model');
         $table_model_names = array_merge($table_model_names, $found_models);
     }
     // convert model name into table model instance
     $table_models = array();
     foreach ($table_model_names as $model_name) {
         $model = $this->getModel($model_name);
         if ($model && $model instanceof Charcoal_ITableModel) {
             $table_models[$model_name] = $model;
         }
     }
     return $table_models;
 }