Esempio n. 1
0
 /**
  * Initialize DbTable for each loaded module.
  *
  * @return void
  */
 protected function _initDbTable()
 {
     $cache = $this->_getCache('core');
     if (!($references = $cache->load('references_apps'))) {
         $this->bootstrap('FrontController');
         $this->bootstrap('db');
         $this->bootstrap('modules');
         $front = $this->getResource('FrontController');
         $modules = $front->getControllerDirectory();
         $references = array();
         $moduleEnabled = Centurion_Config_Manager::get('resources.modules');
         foreach ($modules as $moduleName => $module) {
             if (!in_array($moduleName, $moduleEnabled)) {
                 continue;
             }
             $dbTableDir = realpath($module . '/../models/DbTable');
             if (!file_exists($dbTableDir)) {
                 continue;
             }
             $dir = new Centurion_Iterator_DbTableFilter($dbTableDir);
             foreach ($dir as $fileInfo) {
                 $filename = $fileInfo->getFilenameWithoutExtension();
                 $className = sprintf('%s_Model_DbTable_%s', ucfirst($moduleName), $filename);
                 $model = Centurion_Db::getSingletonByClassName($className);
                 $meta = $model->getMeta();
                 $metaData = $model->info('metadata');
                 foreach ($model->getReferenceMap() as $key => $referenceMap) {
                     $refTableClass = $referenceMap['refTableClass'];
                     $referencedModel = Centurion_Db::getSingletonByClassName($refTableClass);
                     $plural = true;
                     if (isset($metaData[$referenceMap['columns']]['UNIQUE']) && $metaData[$referenceMap['columns']]['UNIQUE'] == true) {
                         $plural = false;
                     }
                     if ($plural) {
                         $dependentTableKey = $meta['verbosePlural'];
                     } else {
                         $dependentTableKey = $meta['verboseName'];
                     }
                     if (array_key_exists($dependentTableKey, $referencedModel->getDependentTables())) {
                         continue;
                     }
                     if (!array_key_exists($refTableClass, $references)) {
                         $references[$refTableClass] = array();
                     }
                     $references[$refTableClass][$dependentTableKey] = $className;
                 }
             }
         }
         $cache->save($references, 'references_apps');
     }
     Centurion_Db::setReferences($references);
 }