Пример #1
0
 public function &addAssociated($association_id, $options = array())
 {
     $default_options = array('class_name' => empty($options['class_name']) ? AkInflector::classify($association_id) : $options['class_name'], 'conditions' => false, 'order' => false, 'include_conditions_when_included' => true, 'include_order_when_included' => true, 'foreign_key' => false, 'dependent' => 'nullify', 'finder_sql' => false, 'counter_sql' => false, 'include' => false, 'instantiate' => false, 'group' => false, 'limit' => false, 'offset' => false, 'handler_name' => strtolower(AkInflector::underscore(AkInflector::singularize($association_id))), 'select' => false);
     $options = array_merge($default_options, $options);
     $options['foreign_key'] = empty($options['foreign_key']) ? AkInflector::underscore($this->Owner->getModelName()) . '_id' : $options['foreign_key'];
     $Collection =& $this->_setCollectionHandler($association_id, $options['handler_name']);
     $Collection->setOptions($association_id, $options);
     $this->addModel($association_id, $Collection);
     if ($options['instantiate']) {
         $associated =& $Collection->load();
     }
     $this->setAssociatedId($association_id, $options['handler_name']);
     $Collection->association_id = $association_id;
     return $Collection;
 }
Пример #2
0
 function _get_default_full_menu()
 {
     $controller_file_names = Ak::dir(AK_CONTROLLERS_DIR, array('files' => false));
     krsort($controller_file_names);
     $menu_options = array();
     foreach ($controller_file_names as $controller_file_name => $options) {
         $controller_file_name = array_pop($options);
         $controller_name = str_replace('.php', '', $controller_file_name);
         if (file_exists(AK_CONTROLLERS_DIR . DS . $controller_file_name)) {
             include_once AK_CONTROLLERS_DIR . DS . $controller_file_name;
             $controller_class_name = AkInflector::classify($controller_name);
             $menu_options[str_replace('_controller', '', $controller_name)] = $this->_get_this_class_methods($controller_class_name);
         }
     }
     return $menu_options;
 }
Пример #3
0
 public function _get_default_full_menu()
 {
     $controllers_dir = AkConfig::getDir('controllers');
     $controller_file_names = array_map('array_pop', (array) AkFileSystem::dir($controllers_dir, array('files' => false)));
     sort($controller_file_names);
     $menu_options = array();
     foreach ($controller_file_names as $controller_file_name) {
         $controller_name = str_replace('.php', '', $controller_file_name);
         if (strstr($controller_file_name, '_controller.php') && file_exists($controllers_dir . DS . $controller_file_name)) {
             include_once $controllers_dir . DS . $controller_file_name;
             $controller_class_name = AkInflector::classify($controller_name);
             $menu_options[str_replace('_controller', '', $controller_name)] = $this->_get_this_class_methods($controller_class_name);
         }
     }
     return $menu_options;
 }
Пример #4
0
 function clear($table, $environment = AK_ENVIRONMENT)
 {
     $modelName = AkInflector::singularize(AkInflector::classify($table));
     $cacheFileName = AkDbSchemaCache::_generateCacheFileName($modelName, $environment);
     //echo "Cleaning cache: $cacheFileName\n";
     if (file_exists($cacheFileName)) {
         @unlink($cacheFileName);
     }
     AkDbSchemaCache::_get($modelName, $environment, false, false);
     $tableName = AkInflector::tableize($table);
     $databaseInternalsFileName = AkDbSchemaCache::_generateCacheFileName('database_table_internals_' . $tableName);
     //echo "Cleaning cache: $databaseInternalsFileName\n";
     if (file_exists($databaseInternalsFileName)) {
         @unlink($databaseInternalsFileName);
     }
     AkDbSchemaCache::_get('database_table_internals_' . $tableName, $environment, false, false);
 }
Пример #5
0
 function populateTables()
 {
     
     $args = func_get_args();
     $tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array();
     foreach ($tables as $table){
         $file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml';
         if(!file_exists($file)){
             continue;
         }
         $class_name = AkInflector::classify($table);
         if($this->instantiateModel($class_name)){
             $contents = &Ak::getStaticVar('yaml_fixture_'.$file);
             if (!$contents) {
                 ob_start();
                 require_once($file);
                 $contents = ob_get_clean();
                 Ak::setStaticVar('yaml_fixture_'.$file, $contents);
             }
             $items = Ak::convert('yaml','array',$contents);
             foreach ($items as $item){
                 
                 $obj=&$this->{$class_name}->create($item);
                 if (isset($item['created_at'])) {
                     $obj->updateAttribute('created_at',$item['created_at']);
                 } else if (isset($item['created_on'])) {
                     $obj->updateAttribute('created_on',$item['created_on']);
                 }
             }
         }
     }
 }
Пример #6
0
 function _getIncludedControllerNames()
 {
     $controllers = array();
     foreach (get_included_files() as $file_name) {
         if (strstr($file_name, AK_CONTROLLERS_DIR)) {
             $controllers[] = AkInflector::classify(str_replace(array(AK_CONTROLLERS_DIR . DS, '.php', DS, '//'), array('', '', '/', '/'), $file_name));
         }
     }
     return $controllers;
 }
Пример #7
0
 function dropTable($table_name, $options = array())
 {
     require_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkDbSchemaCache.php');
     AkDbSchemaCache::clear(AkInflector::classify($table_name));
     $result = $this->tableExists($table_name) ? $this->db->execute('DROP TABLE '.$table_name) : true;
     if($result){
         unset($this->available_tables[array_search($table_name, $this->available_tables)]);
         if(!empty($options['sequence'])){
             $this->dropSequence($table_name);
         }
     }
 }
Пример #8
0
 public function &addAssociated($association_id, $options = array())
 {
     $default_options = array('class_name' => empty($options['class_name']) ? AkInflector::classify($association_id) : $options['class_name'], 'table_name' => false, 'join_table' => false, 'join_class_name' => false, 'foreign_key' => false, 'association_foreign_key' => false, 'conditions' => false, 'order' => false, 'join_class_extends' => AK_HAS_AND_BELONGS_TO_MANY_JOIN_CLASS_EXTENDS, 'join_class_primary_key' => 'id', 'finder_sql' => false, 'delete_sql' => false, 'insert_sql' => false, 'include' => false, 'group' => false, 'limit' => false, 'offset' => false, 'handler_name' => strtolower(AkInflector::underscore(AkInflector::singularize($association_id))), 'select' => false, 'instantiate' => false, 'unique' => false);
     $options = array_merge($default_options, $options);
     $owner_name = $this->Owner->getModelName();
     $owner_table = $this->Owner->getTableName();
     $associated_name = $options['class_name'];
     $associated_table_name = $options['table_name'] = empty($options['table_name']) ? AkInflector::tableize($associated_name) : $options['table_name'];
     $join_tables = array($owner_table, $associated_table_name);
     sort($join_tables);
     $options['join_table'] = empty($options['join_table']) ? join('_', $join_tables) : $options['join_table'];
     $options['join_class_name'] = empty($options['join_class_name']) ? join(array_map(array('AkInflector', 'classify'), array_map(array('AkInflector', 'singularize'), $join_tables))) : $options['join_class_name'];
     $options['foreign_key'] = empty($options['foreign_key']) ? AkInflector::underscore($owner_name) . '_id' : $options['foreign_key'];
     $options['association_foreign_key'] = empty($options['association_foreign_key']) ? AkInflector::underscore($associated_name) . '_id' : $options['association_foreign_key'];
     $Collection =& $this->_setCollectionHandler($association_id, $options['handler_name']);
     $Collection->setOptions($association_id, $options);
     $this->addModel($association_id, $Collection);
     if ($options['instantiate']) {
         $associated =& $Collection->load();
     }
     $this->setAssociatedId($association_id, $options['handler_name']);
     $Collection->association_id = $association_id;
     $Collection->_loadJoinObject();
     return $Collection;
 }
Пример #9
0
 function getApplicationHelpers()
 {
     $helper_names = array();
     if ($this->app_helpers == 'all') {
         $available_helpers = Ak::dir(AK_HELPERS_DIR, array('dirs' => false));
         $helper_names = array();
         foreach ($available_helpers as $available_helper) {
             $helper_names[$available_helper] = AkInflector::classify(substr($available_helper, 0, -10));
         }
     } elseif (is_string($this->app_helpers)) {
         foreach (Ak::toArray($this->app_helpers) as $helper_name) {
             $helper_names[AK_HELPERS_DIR . DS . AkInflector::underscore($helper_name) . '_helper.php'] = AkInflector::classify($helper_name);
         }
     }
     return $helper_names;
 }
Пример #10
0
    function _initSweeper($sweeper, $options = array())
    {
        if (!empty($options['only']) && !in_array($this->_controller->getActionName(), $options['only'])) return;
        if (!empty($options['except']) && !in_array($this->_controller->getActionName(), $options['except'])) return;

        $sweeper_class = AkInflector::classify($sweeper);

        if (!class_exists($sweeper_class)) {
            $filePath = AK_APP_DIR . DS . 'sweepers' . DS . $sweeper.'.php';
            if (file_exists($filePath)) {
                require_once($filePath);
                if (!class_exists($sweeper_class)) {
                    trigger_error('Cache Sweeper "' . $sweeper_class . '" does not exist in: ' . $filePath, E_USER_ERROR);
                }
            } else if (AK_ENVIRONMENT == 'development') {
                trigger_error('Cache Sweeper file does not exist: ' . $filePath, E_USER_ERROR);
            }
        }
        $this->_Sweepers[] = &new $sweeper_class(&$this);
    }
Пример #11
0
 function Test_of_classify()
 {
     foreach ($this->ClassNameToTableName as $class_name => $table_name) {
         $this->assertEqual($class_name, AkInflector::classify($table_name));
     }
 }
Пример #12
0
 function _getFilterClassName($filter_name)
 {
     // We might allow other classes to be created as filters in order to create image filter plugins from outside the framework
     if (!class_exists($filter_name)) {
         return 'AkImage' . AkInflector::classify($filter_name) . 'Filter';
     } else {
         return $filter_name;
     }
 }
Пример #13
0
 function populateTables()
 {
     $args = func_get_args();
     $tables = !empty($args) ? is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args)) : array();
     foreach ($tables as $table) {
         $file = AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . (empty($this->module) ? '' : $this->module . DS) . Ak::sanitize_include($table) . '.yaml';
         if (!file_exists($file)) {
             continue;
         }
         $class_name = AkInflector::classify($table);
         if ($this->instantiateModel($class_name)) {
             $items = Ak::convert('yaml', 'array', file_get_contents($file));
             foreach ($items as $item) {
                 $this->{$class_name}->create($item);
             }
         }
     }
 }
Пример #14
0
 function getApplicationHelperNames()
 {
     $handler =& $this->_Handler;
     $handler->app_helpers = !isset($handler->app_helpers) ? null : $handler->app_helpers;
     $helper_names = array();
     if ($handler->app_helpers == 'all') {
         $available_helpers = Ak::dir(AK_HELPERS_DIR, array('dirs' => false));
         $helper_names = array();
         foreach ($available_helpers as $available_helper) {
             $helper_names[AK_HELPERS_DIR . DS . $available_helper] = AkInflector::classify(substr($available_helper, 0, -10));
         }
     } elseif (!empty($handler->app_helpers)) {
         foreach (Ak::toArray($handler->app_helpers) as $helper_name) {
             $helper_names[AK_HELPERS_DIR . DS . AkInflector::underscore($helper_name) . '_helper.php'] = AkInflector::camelize($helper_name);
         }
     }
     return $helper_names;
 }
Пример #15
0
 public function _getIncludedControllerNames()
 {
     $controllers = array();
     foreach (get_included_files() as $file_name) {
         if (strstr($file_name, AkConfig::getDir('controllers'))) {
             $controllers[] = AkInflector::classify(str_replace(array(AkConfig::getDir('controllers') . DS, '.php', DS, '//'), array('', '', '/', '/'), $file_name));
         }
     }
     return $controllers;
 }
Пример #16
0
 public function getApplicationHelperNames()
 {
     $handler = $this->_Handler;
     $handler->app_helpers = !isset($handler->app_helpers) ? 'all' : $handler->app_helpers;
     $helpers_dir = AkConfig::getDir('helpers');
     $helper_names = array();
     if ($handler->app_helpers == 'all') {
         $available_helpers = AkFileSystem::dir($helpers_dir, array('dirs' => false));
         $helper_names = array();
         foreach ($available_helpers as $available_helper) {
             $helper_names[$helpers_dir . DS . $available_helper] = AkInflector::classify(substr($available_helper, 0, -10));
         }
     } elseif (!empty($handler->app_helpers)) {
         foreach (Ak::toArray($handler->app_helpers) as $helper_name) {
             $helper_names[$helpers_dir . DS . AkInflector::underscore($helper_name) . '_helper.php'] = AkInflector::camelize($helper_name);
         }
     }
     return $helper_names;
 }