function test_should_establish_multiple_connections()
    {
        if(AK_PHP5){
            $db_settings = Ak::convert('yaml', 'array', AK_CONFIG_DIR.DS.'database.yml');
            $db_settings['sqlite_databases'] = array(
                    'database_file' => AK_TMP_DIR.DS.'testing_sqlite_database.sqlite',
                    'type' => 'sqlite'
                    );
            file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
        
       
            $this->installAndIncludeModels(array('TestOtherConnection'));

            Ak::import('test_other_connection');
            $OtherConnection = new TestOtherConnection(array('name'=>'Delia'));
            $this->assertTrue($OtherConnection->save());
        
        
            $this->installAndIncludeModels(array('DummyModel'=>'id,name'));
            $Dummy = new DummyModel();
        
            $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
        
            unset($db_settings['sqlite_databases']);
            file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
        }
    }
Esempio n. 2
0
 public function test_start()
 {
     $this->installAndIncludeModels(array(
     'Category'=>'id, parent_id, description, department string(25)'
     ));
     Ak::import('DependentCategory');
 }
Esempio n. 3
0
 public function test_start()
 {
     eval("class ObservedAccount extends AkActiveRecord { public \$notified_observers = array();} ");
     eval("class ObservedPerson extends AkActiveRecord { public \$notified_observers = array();} ");
     $this->installAndIncludeModels(array('ObservedAccount' => 'id, balance, created_at, updated_at', 'ObservedPerson' => 'id, user_name, first_name, last_name, city, state'));
     Ak::import('TestAuditor', 'ObservedPersonObserver');
 }
Esempio n. 4
0
 public function test_start()
 {
     $this->installAndIncludeModels(array(
     'ObservedAccount'=>'id, balance, created_at, updated_at',
     'ObservedPerson'=>'id, user_name, first_name, last_name, city, state'));
     Ak::import('TestAuditor','ObservedPersonObserver');
 }
Esempio n. 5
0
 function test_setup()
 {
     $this->uninstallAndInstallMigration('AdminPlugin');
     Ak::import('extension');
     $this->Extension =& new Extension();
     $this->populateTables('extensions');
 }
Esempio n. 6
0
 function authenticate()
 {
     Ak::import('sentinel');
     $Sentinel =& new Sentinel();
     $Sentinel->init($this);
     return $Sentinel->authenticate();
 }
Esempio n. 7
0
 function &updateClassDetails(&$File, &$Component, &$SourceAnalyzer)
 {
     Ak::import('method');
     $MethodInstance =& new Method();
     $parsed_details = $SourceAnalyzer->getParsedArray($File->body);
     $available_classes = empty($parsed_details['classes']) ? array() : array_keys($parsed_details['classes']);
     if (empty($available_classes)) {
         return $available_classes;
     }
     $Classes = array();
     foreach ($available_classes as $class_name) {
         $extends = !empty($parsed_details['classes'][$class_name]['extends']) ? $parsed_details['classes'][$class_name]['extends'] : false;
         if ($extends) {
             $SourceAnalyzer->log('Looking for parent class: ' . $extends);
             $ParentClass =& $this->_addOrUpdateClassDetails($extends, $File, $Component, $SourceAnalyzer, array(), true);
         }
         $Class =& $this->_addOrUpdateClassDetails($class_name, $File, $Component, $SourceAnalyzer, $parsed_details['classes'][$class_name]);
         if (!empty($ParentClass)) {
             $SourceAnalyzer->log('Setting ' . $extends . ' as the parent of ' . $class_name);
             $ParentClass->tree->addChild($Class);
             $ParentClass->save();
         }
         $Class->methods = array();
         if (!empty($parsed_details['classes'][$class_name]['methods'])) {
             foreach ($parsed_details['classes'][$class_name]['methods'] as $method_name => $method_details) {
                 $Class->methods[] =& $MethodInstance->updateMethodDetails($Class, $method_name, $method_details, $SourceAnalyzer);
             }
         }
         $Classes[] =& $Class;
     }
     return $Classes;
 }
Esempio n. 8
0
 public function addDefaults()
 {
     if (AK_ENVIRONMENT == 'testing') {
         return;
     }
     Ak::import('User', 'Role', 'Permission', 'Extension');
     $this->createExtensions();
     $this->createRoles();
     $this->createAdministrator();
 }
Esempio n. 9
0
 public function test_for_importing_models()
 {
     $models = 'ImportTestModelA, import_test_model_b';
     $this->assertEqual(Ak::import($models), array('ImportTestModelA', 'ImportTestModelB'));
     $this->assertTrue(class_exists('ImportTestModelA'));
     $this->assertTrue(class_exists('ImportTestModelB'));
     $models = array('ImportTestModelB', 'Import Test Model C');
     $this->assertEqual(Ak::import($models), array('ImportTestModelB', 'ImportTestModelC'));
     $this->assertTrue(class_exists('ImportTestModelC'));
 }
Esempio n. 10
0
function akelos_autoload($name, $path = null)
{
    static $paths = array(), $lib_paths = array(), $app_paths = array();
    if (!empty($path)) {
        $paths[$name] = $path;
        return;
    }
    if (empty($app_paths)) {
        $app_paths = array('BaseActionController' => 'controllers/base_action_controller.php', 'BaseActiveRecord' => 'models/base_active_record.php', 'ApplicationController' => 'controllers/application_controller.php', 'ActiveRecord' => 'models/active_record.php');
    }
    if (empty($lib_paths)) {
        $lib_paths = array('AkActionMailer' => 'action_mailer/base.php', 'AkMailComposer' => 'action_mailer/composer.php', 'AkMailEncoding' => 'action_mailer/encoding.php', 'AkMailBase' => 'action_mailer/mail_base.php', 'AkMailMessage' => 'action_mailer/message.php', 'AkMailParser' => 'action_mailer/parser.php', 'AkMailPart' => 'action_mailer/part.php', 'AkActionMailerQuoting' => 'action_mailer/quoting.php', 'AkActionController' => 'action_pack/action_controller.php', 'AkExceptionDispatcher' => 'action_pack/exception_dispatcher.php', 'AkActionView' => 'action_pack/action_view.php', 'AkBaseHelper' => 'action_pack/base_helper.php', 'AkActionViewHelper' => 'action_pack/base_helper.php', 'AkCacheHandler' => 'action_pack/cache_handler.php', 'AkCacheSweeper' => 'action_pack/cache_sweeper.php', 'AkActionControllerTest' => 'action_pack/testing.php', 'AkHelperTest' => 'action_pack/testing.php', 'AkDbSession' => 'action_pack/db_session.php', 'AkCookieStore' => 'action_pack/cookie_store.php', 'AkDispatcher' => 'action_pack/dispatcher.php', 'AkActiveRecordHelper' => 'action_pack/helpers/ak_active_record_helper.php', 'AkAssetTagHelper' => 'action_pack/helpers/ak_asset_tag_helper.php', 'AkFormHelperBuilder' => 'action_pack/helpers/ak_form_helper.php', 'AkFormHelperInstanceTag' => 'action_pack/helpers/ak_form_helper.php', 'AkFormHelper' => 'action_pack/helpers/ak_form_helper.php', 'AkFormHelperOptionsInstanceTag' => 'action_pack/helpers/ak_form_options_helper.php', 'AkFormTagHelper' => 'action_pack/helpers/ak_form_tag_helper.php', 'AkJavascriptHelper' => 'action_pack/helpers/ak_javascript_helper.php', 'AkJavascriptMacrosHelper' => 'action_pack/helpers/ak_javascript_macros_helper.php', 'AkMailHelper' => 'action_pack/helpers/ak_mail_helper.php', 'AkMenuHelper' => 'action_pack/helpers/ak_menu_helper.php', 'AkNumberHelper' => 'action_pack/helpers/ak_number_helper.php', 'AkPaginationHelper' => 'action_pack/helpers/ak_pagination_helper.php', 'AkPrototypeHelper' => 'action_pack/helpers/ak_prototype_helper.php', 'AkScriptaculousHelper' => 'action_pack/helpers/ak_scriptaculous_helper.php', 'AkTextHelper' => 'action_pack/helpers/ak_text_helper.php', 'AkUrlHelper' => 'action_pack/helpers/ak_url_helper.php', 'AkXmlHelper' => 'action_pack/helpers/ak_xml_helper.php', 'AkHelperLoader' => 'action_pack/helper_loader.php', 'AkPaginator' => 'action_pack/pagination.php', 'AkPhpCodeSanitizer' => 'action_pack/php_code_sanitizer.php', 'AkPhpTemplateHandler' => 'action_pack/php_template_handler.php', 'AkRequest' => 'action_pack/request.php', 'AkResponse' => 'action_pack/response.php', 'AkRouter' => 'action_pack/router/base.php', 'AkDynamicSegment' => 'action_pack/router/dynamic_segment.php', 'AkLangSegment' => 'action_pack/router/lang_segment.php', 'AkRoute' => 'action_pack/router/route.php', 'AkRouterConfig' => 'action_pack/router/router_config.php', 'AkRouterHelper' => 'action_pack/router/router_helper.php', 'AkSegment' => 'action_pack/router/segment.php', 'AkStaticSegment' => 'action_pack/router/static_segment.php', 'AkUrl' => 'action_pack/router/url.php', 'AkUrlWriter' => 'action_pack/router/url_writer.php', 'AkVariableSegment' => 'action_pack/router/variable_segment.php', 'AkWildcardSegment' => 'action_pack/router/wildcard_segment.php', 'AkResource' => 'action_pack/router/resources.php', 'AkResources' => 'action_pack/router/resources.php', 'AkSingletonResource' => 'action_pack/router/resources.php', 'AkSession' => 'action_pack/session.php', 'AkStream' => 'action_pack/stream.php', 'AkSintags' => 'action_pack/template_engines/sintags/base.php', 'AkSintagsLexer' => 'action_pack/template_engines/sintags/lexer.php', 'AkSintagsParser' => 'action_pack/template_engines/sintags/parser.php', 'AkXhtmlValidator' => 'action_pack/xhtml_validator.php', 'AkActionWebService' => 'action_pack/action_web_service.php', 'AkActionWebserviceApi' => 'action_pack/action_web_service/api.php', 'AkActionWebServiceClient' => 'action_pack/action_web_service/client.php', 'AkActionWebServiceServer' => 'action_pack/action_web_service/server.php', 'AkActiveRecord' => 'active_record/base.php', 'AkDbAdapter' => 'active_record/adapters/base.php', 'AkAssociatedActiveRecord' => 'active_record/associated_active_record.php', 'AkAssociation' => 'active_record/associations/base.php', 'AkBelongsTo' => 'active_record/associations/belongs_to.php', 'AkHasAndBelongsToMany' => 'active_record/associations/has_and_belongs_to_many.php', 'AkHasMany' => 'active_record/associations/has_many.php', 'AkHasOne' => 'active_record/associations/has_one.php', 'AkDbSchemaCache' => 'active_record/database_schema_cache.php', 'AkActiveRecordMock' => 'active_record/mock.php', 'AkObserver' => 'active_record/observer.php', 'AkHttpClient' => 'active_resource/http_client.php', 'AkAdodbCache' => 'active_support/cache/adodb.php', 'AkCache' => 'active_support/cache/base.php', 'AkMemcache' => 'active_support/cache/memcache.php', 'AkColor' => 'active_support/color/base.php', 'AkConsole' => 'active_support/console/base.php', 'AkAnsiColor' => 'active_support/console/ansi.php', 'AkConfig' => 'active_support/config/base.php', 'AkClassExtender' => 'active_support/core/class_extender.php', 'AkDebug' => 'active_support/core/debug.php', 'AkLazyObject' => 'active_support/core/lazy_object.php', 'AkArray' => 'active_support/core/types/array.php', 'AkType' => 'active_support/core/types/base.php', 'AkDate' => 'active_support/core/types/date.php', 'AkMimeType' => 'active_support/core/types/mime.php', 'AkNumber' => 'active_support/core/types/number.php', 'AkString' => 'active_support/core/types/string.php', 'AkTime' => 'active_support/core/types/time.php', 'AkFileSystem' => 'active_support/file_system/base.php', 'AkelosGenerator' => 'active_support/generator.php', 'AkCharset' => 'active_support/i18n/charset/base.php', 'AkCountries' => 'active_support/i18n/countries.php', 'AkLocaleManager' => 'active_support/i18n/locale_manager.php', 'AkTimeZone' => 'active_support/i18n/time_zone.php', 'AkImage' => 'active_support/image/base.php', 'AkImageColorScheme' => 'active_support/image/color_scheme.php', 'AkImageFilter' => 'active_support/image/filters/base.php', 'AkLogger' => 'active_support/logger.php', 'AkInstaller' => 'active_support/migrations/installer.php', 'AkBaseModel' => 'active_support/models/base.php', 'AkModelExtenssion' => 'active_support/models/base.php', 'AkFtp' => 'active_support/network/ftp.php', 'AkPlugin' => 'active_support/plugin/base.php', 'AkPluginLoader' => 'active_support/plugin/base.php', 'AkPluginInstaller' => 'active_support/plugin/installer.php', 'AkPluginManager' => 'active_support/plugin/manager.php', 'AkProfiler' => 'active_support/profiler.php', 'AkReflection' => 'active_support/reflection/base.php', 'AkReflectionClass' => 'active_support/reflection/class.php', 'AkReflectionDocBlock' => 'active_support/reflection/doc_block.php', 'AkReflectionFile' => 'active_support/reflection/file.php', 'AkReflectionFunction' => 'active_support/reflection/function.php', 'AkReflectionMethod' => 'active_support/reflection/method.php', 'AkTestApplication' => 'active_support/testing/application.php', 'AkelosTextReporter' => 'active_support/testing/base.php', 'AkelosVerboseTextReporter' => 'active_support/testing/base.php', 'AkXUnitXmlReporter' => 'active_support/testing/base.php', 'AkUnitTest' => 'active_support/testing/base.php', 'AkWebTestCase' => 'active_support/testing/base.php', 'AkTestDispatcher' => 'active_support/testing/dispatcher.php', 'AkTestRequest' => 'active_support/testing/request.php', 'AkTestResponse' => 'active_support/testing/response.php', 'AkUnitTestSuite' => 'active_support/testing/suite.php', 'AkRouterUnitTest' => 'active_support/testing/router.php', 'AkRouteUnitTest' => 'active_support/testing/route.php', 'AkControllerUnitTest' => 'active_support/testing/controller.php', 'AkInflector' => 'active_support/text/inflector.php', 'AkLexer' => 'active_support/text/lexer.php', 'AkError' => 'active_support/error_handlers/base.php', 'AkActiveDocument' => 'active_document/base.php', 'AkOdbAdapter' => 'active_document/adapters/base.php');
    }
    if (isset($lib_paths[$name])) {
        include AK_FRAMEWORK_DIR . DS . $lib_paths[$name];
        return;
    }
    if (isset($app_paths[$name])) {
        $file_path = AkConfig::getDir('app') . DS . $app_paths[$name];
        if (file_exists($file_path)) {
            include $file_path;
            return;
        }
    }
    if (isset($paths[$name])) {
        include $paths[$name];
    } elseif (file_exists(DS . $name . '.php')) {
        include DS . $name . '.php';
    } else {
        $underscored_name = AkInflector::underscore($name);
        if (!Ak::import($name)) {
            if (strstr($name, 'Helper')) {
                $file_path = AkConfig::getDir('helpers') . DS . $underscored_name . '.php';
                if (!file_exists($file_path)) {
                    $file_path = AK_ACTION_PACK_DIR . DS . 'helpers' . DS . $underscored_name . '.php';
                    if (!file_exists($file_path)) {
                        $file_path = AK_ACTION_PACK_DIR . DS . 'helpers' . DS . 'ak_' . $underscored_name . '.php';
                        if (include_once $file_path) {
                            eval('class ' . $name . ' extends Ak' . $name . '{}');
                            return;
                        }
                    }
                }
            } elseif (strstr($name, 'Installer')) {
                $file_path = AkConfig::getDir('app_installers') . DS . $underscored_name . '.php';
            } elseif (strstr($name, 'Controller')) {
                $file_path = AkInflector::toControllerFilename($name);
            }
        }
    }
    if (isset($file_path) && file_exists($file_path)) {
        include $file_path;
    }
}
Esempio n. 11
0
 function __test_should_extract_javadoc_blocks()
 {
     $SourceAnalyzer = new SourceAnalyzer();
     include_once AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . 'parsed.php';
     $SourceAnalyzer->importCategories($parsed['categories']);
     unset($parsed['categories']);
     Ak::import('akelos_class');
     $ClassInstance =& new AkelosClass();
     foreach ($parsed as $class_name => $details) {
         if (!($Class =& $ClassInstance->findFirstBy('name', $class_name))) {
             echo "<pre>" . print_r($details, true) . "</pre>";
             $Class =& new AkelosClass(array('name' => $class_name));
             $this->assertTrue($Class->save());
         }
     }
     //      print_r($parsed);
 }
Esempio n. 12
0
 function importCategories($categories)
 {
     Ak::import('category');
     $CategoryInstance =& new Category();
     foreach ($categories as $category_name => $related) {
         if (!($Category =& $CategoryInstance->findFirstBy('name', $category_name))) {
             $Category =& new Category(array('name' => $category_name));
             if ($Category->save()) {
                 $this->log('Created new category: ' . $category_name);
             }
         }
         if (!empty($related['relations'])) {
             foreach ($related['relations'] as $related_category) {
                 if (!($RelatedCategory =& $CategoryInstance->findFirstBy('name', $related_category))) {
                     $RelatedCategory =& new Category(array('name' => $related_category));
                     $RelatedCategory->save();
                 }
                 $this->log('Relating category ' . $related_category . ' with ' . $category_name);
                 $Category->related_category->add($RelatedCategory);
             }
         }
     }
 }
Esempio n. 13
0
 public function test_should_establish_multiple_connections()
 {
     $db_file_existed = false;
     if (file_exists(AkConfig::getDir('config') . DS . 'database.yml')) {
         $db_file_existed = true;
         $db_settings = Ak::convert('yaml', 'array', AkConfig::getDir('config') . DS . 'database.yml');
     }
     $db_settings['sqlite_databases'] = array('database_file' => AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite', 'type' => 'sqlite');
     file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings));
     @unlink(AK_TMP_DIR . DS . 'testing_sqlite_database.sqlite');
     $this->installAndIncludeModels(array('TestOtherConnection'));
     Ak::import('test_other_connection');
     $OtherConnection = new TestOtherConnection(array('name' => 'Delia'));
     $this->assertTrue($OtherConnection->save());
     $this->installAndIncludeModels(array('DummyModel' => 'id,name'));
     $Dummy = new DummyModel();
     $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
     unset($db_settings['sqlite_databases']);
     if ($db_file_existed) {
         file_put_contents(AkConfig::getDir('config') . DS . 'database.yml', Ak::convert('array', 'yaml', $db_settings));
     } else {
         unlink(AkConfig::getDir('config') . DS . 'database.yml');
     }
 }
Esempio n. 14
0
 function instantiateIncludedModelClasses($models = array())
 {
     require_once AK_LIB_DIR . DS . 'AkActiveRecord.php';
     require_once AK_APP_DIR . DS . 'shared_model.php';
     empty($this->model) ? $this->model = $this->params['controller'] : null;
     empty($this->models) ? $this->models = array() : null;
     $models = array_unique(array_merge(Ak::import($this->model), Ak::import($this->models), Ak::import($models), empty($this->app_models) ? array() : Ak::import($this->app_models)));
     foreach ($models as $model) {
         $this->instantiateModelClass($model, empty($this->finder_options[$model]) ? array() : $this->finder_options[$model]);
     }
 }
Esempio n. 15
0
 public function &getAssociatedModelInstance()
 {
     static $ModelInstances;
     $class_name = $this->getOption($this->association_id, 'class_name');
     if (empty($ModelInstances[$class_name])) {
         Ak::import($class_name);
         $ModelInstances[$class_name] = new $class_name();
     }
     return $ModelInstances[$class_name];
 }
Esempio n. 16
0
 function instantiateIncludedModelClasses($models = null)
 {
     require_once AK_LIB_DIR . DS . 'AkActiveRecord.php';
     require_once AK_APP_DIR . DS . 'shared_model.php';
     $models = empty($models) ? array_unique(array_merge(Ak::import($this->model), Ak::import($this->models))) : $models;
     foreach ($models as $model) {
         $this->instantiateModelClass($model);
     }
 }
Esempio n. 17
0
    function instantiateIncludedModelClasses($models = array())
    {
        require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');
        require_once(AK_APP_DIR.DS.'shared_model.php');

        empty($this->model) ? ($this->model = $this->params['controller']) : null;
        empty($this->models) ? ($this->models = array()) : null;

        $models = array_unique(array_merge(Ak::import($this->model), Ak::import($this->models), Ak::import($models), (empty($this->app_models)?array(): Ak::import($this->app_models))));

        unset($this->model, $this->models);
        $getFinderOptionsExists=method_exists($this,'_getFinderOptions');
        foreach ($models as $model){
            $custom_find = false;
            if (empty($this->finder_options[$model]) && $getFinderOptionsExists) {
                $this->finder_options[$model] = $this->_getFinderOptions($model);
                $custom_find=true;
            }
            $this->instantiateModelClass($model, (empty($this->finder_options[$model])?array():$this->finder_options[$model]),$custom_find);
        }
    }
Esempio n. 18
0
 public function _prepareIncludes($prefix, $parent_is_plural, &$parent, &$available_associated_options, $handler_name, $parent_association_id, $association_id, &$options, &$association_options, &$replacements, &$config)
 {
     if (isset($association_options['include'])) {
         $association_options['include'] = Ak::toArray($association_options['include']);
         if (isset($parent->{$handler_name}) && method_exists($parent->{$handler_name}, 'getModelName')) {
             $main_association_class_name = $parent->{$handler_name}->getModelName();
             Ak::import($main_association_class_name);
             $sub_association_object = new $main_association_class_name();
         } else {
             if (isset($parent->{$handler_name}) && method_exists($parent->{$handler_name}, 'getAssociatedModelInstance')) {
                 $sub_association_object =& $parent->{$handler_name}->getAssociatedModelInstance();
             } else {
                 $sub_association_object =& $parent;
             }
         }
     } else {
         /**
          * No included associations
          */
         return;
     }
     foreach ($association_options['include'] as $idx => $sub_association_id) {
         if (!is_numeric($idx) && is_array($sub_association_id)) {
             $sub_options = $sub_association_id;
             $sub_association_id = $idx;
         } else {
             $sub_options = array();
         }
         $sub_handler_name = $sub_association_object->getCollectionHandlerName($sub_association_id);
         if (!$sub_handler_name) {
             $sub_handler_name = $sub_association_id;
         }
         $type = $sub_association_object->{$sub_handler_name}->getType();
         if ($type == 'hasMany' || $type == 'hasAndBelongsToMany') {
             $instance =& $sub_association_object->{$sub_handler_name}->getAssociatedModelInstance();
             $class_name = $instance->getType();
             $table_name = $instance->getTableName();
             $pk = $instance->getPrimaryKey();
             $pluralize = true;
         } else {
             if ($type == 'belongsTo' || $type == 'hasOne') {
                 $class_name = $sub_association_object->{$sub_handler_name}->getAssociationOption('class_name');
                 if (!class_exists($class_name)) {
                     Ak::import($class_name);
                 }
                 $instance = new $class_name();
                 $table_name = $instance->getTableName();
                 $pk = $instance->getPrimaryKey();
                 $pluralize = false;
             } else {
                 $pk = $sub_association_object->{$sub_handler_name}->getPrimaryKey();
                 $instance =& $sub_association_object;
                 $class_name = $instance->getType();
                 $pluralize = false;
                 $table_name = $instance->getTableName();
             }
         }
         $config[$handler_name][$sub_handler_name] = array('association_id' => $sub_association_id, 'class' => $class_name, 'pk' => $pk, 'instance' => $instance);
         $sub_associated_options = $sub_association_object->{$sub_handler_name}->getAssociatedFinderSqlOptionsForInclusionChain($prefix . '[' . $handler_name . ']' . ($parent_is_plural ? '[@' . $pk . ']' : ''), '__owner__' . $parent_association_id, $sub_options, $pluralize);
         /**
          * Adding replacements for base options like order,conditions,group.
          * The table-aliases of the included associations will be replaced
          * with their respective __owner_$handler_name.$column_name representative.
          */
         $replacements['/([,\\s])_(' . $sub_association_id . ')\\./'] = '\\1__owner__' . $parent_association_id . '__' . $sub_handler_name . '.';
         $replacements['/([,\\s])(' . $sub_association_id . ')\\./'] = '\\1__owner__' . $parent_association_id . '__' . $sub_handler_name . '.';
         $replacements['/([,\\s])_(' . $table_name . ')\\./'] = '\\1__owner__' . $parent_association_id . '__' . $sub_handler_name . '.';
         $replacements['/([,\\s])(' . $table_name . ')\\./'] = '\\1__owner__' . $parent_association_id . '__' . $sub_handler_name . '.';
         $replacements['/([,\\s])_(' . $sub_handler_name . ')\\./'] = '\\1__owner__' . $parent_association_id . '__' . $sub_handler_name . '.';
         $replacements['/([,\\s])(' . $sub_handler_name . ')\\./'] = '\\1__owner__' . $parent_association_id . '__' . $sub_handler_name . '.';
         foreach (array_keys($available_associated_options) as $sub_associated_option) {
             $newoption = isset($sub_associated_options[$sub_associated_option]) ? $sub_associated_options[$sub_associated_option] : '';
             if ($sub_associated_option != 'bind' && $sub_associated_option != 'include') {
                 $newoption = trim($newoption);
                 if (!empty($newoption)) {
                     $available_associated_options[$sub_associated_option][] = $newoption;
                 }
             } else {
                 $available_associated_options[$sub_associated_option] = array_merge((array) $available_associated_options[$sub_associated_option], Ak::toArray($newoption));
             }
         }
         if (!empty($sub_options)) {
             $this->_prepareIncludes($prefix . '[' . $handler_name . ']' . ($parent_is_plural ? '[@' . $pk . ']' : ''), $pluralize, $instance, $available_associated_options, $sub_handler_name, $parent_association_id . '__' . $sub_handler_name, $sub_association_id, $options['include'][$association_id], $association_options['include'][$idx], $replacements, $config[$handler_name]);
         }
     }
 }
Esempio n. 19
0
 function &build($attributes = array(), $set_as_new_record = true)
 {
     $options = $this->getOptions($this->association_id);
     Ak::import($options['class_name']);
     $record =& new $options['class_name']($attributes);
     $record->_newRecord = $set_as_new_record;
     $this->Owner->{$this->association_id}[] =& $record;
     $this->_setAssociatedMemberId($record);
     $this->_relateAssociatedWithOwner($record);
     return $record;
 }
Esempio n. 20
0
    function instantiateIncludedModelClasses()
    {
        require_once(AK_LIB_DIR.DS.'AkActiveRecord.php');
        require_once(AK_APP_DIR.DS.'shared_model.php');

        empty($this->model) ? ($this->model = $this->params['controller']) : null;
        empty($this->models) ? ($this->models = array()) : null;
        
        $models =array_unique(array_merge(
        Ak::import($this->model),
        Ak::import($this->models)));

        foreach ($models as $model){
            $this->instantiateModelClass($model);
        }
    }
Esempio n. 21
0
<?php

Ak::import('Event');

class Concert extends Event
{

}

?>
Esempio n. 22
0
 function instantiateModel($model_name)
 {
     if(class_exists($model_name) || Ak::import($model_name)){
         $this->$model_name =& new $model_name();
     } else {
         trigger_error(Ak::t('Could not instantiate %modelname',array('%modelname'=>$model_name)),E_USER_ERROR);
     }
     return !empty($this->$model_name) && is_object($this->$model_name) && strtolower(get_class($this->$model_name)) == strtolower($model_name);
 }
Esempio n. 23
0
 function &getAssociatedModelInstance()
 {
     static $ModelInstance;
     if(empty($ModelInstance)){
         $class_name = $this->getOption($this->association_id, 'class_name');
         Ak::import($class_name);
         $ModelInstance =& new $class_name();
     }
     return $ModelInstance;
 }
Esempio n. 24
0
 function &build($association_id, $attributes = array(), $replace = true)
 {
     $class_name = $this->Owner->{$association_id}->getAssociationOption('class_name');
     Ak::import($class_name);
     $record =& new $class_name($attributes);
     $record =& $this->Owner->{$association_id}->replace($record);
     return $record;
 }
Esempio n. 25
0
 function instantiateModel($model_name)
 {
     if(empty($this->$model_name)){
         Ak::import($model_name);
         if(class_exists($model_name)){
             $this->$model_name =& new $model_name();
         }
     }
     return !empty($this->$model_name) && is_object($this->$model_name) && strtolower(get_class($this->$model_name)) == strtolower($model_name);
 }
Esempio n. 26
0
File: Ak.php Progetto: joeymetal/v1
 /**
  * Get a models a model instance. Including and instantiating the model for us.
  *
  * This kinds mimics the ideal (new Model())->find() wich does not exist on PHP yet.
  *
  * On Akelos we can do Ak::get('Model')->find();
  */
 public static function get($model_name, $attributes = array())
 {
     $model_name = array_shift(Ak::import($model_name));
     if (!empty($model_name)) {
         return new $model_name($attributes);
     }
 }
Esempio n. 27
0
    function &build($association_id, $attributes = array(), $replace_existing = true)
    {
        $class_name = $this->Owner->$association_id->getAssociationOption('class_name');
        $foreign_key = $this->Owner->$association_id->getAssociationOption('foreign_key');
        Ak::import($class_name);
        $record =& new $class_name($attributes);
        if ($replace_existing){
            $record =& $this->replace($association_id, $record, true);
        }
        if(!$this->Owner->isNewRecord()){
            $record->set($foreign_key, $this->Owner->getId());
        }

        $record =& $this->_build($association_id, &$record);

        return $record;
    }
Esempio n. 28
0
File: Ak.php Progetto: joeymetal/v1
 /**
  * Get a models a model instance. Including and instantiating the model for us.
  *
  * This kinds mimics the ideal (new Model())->find() wich does not exist on PHP yet.
  *
  * On Akelos we can do Ak::get('Model')->find();
  */
 function get($model_name, $attributes = array())
 {
     Ak::import($model_name);
     return new $model_name($attributes);
 }
Esempio n. 29
0
 function _getExtensionId($extension, $force_reload = false)
 {
     static $extenssion_ids = array();
     if (is_string($extension) && !is_numeric($extension)) {
         if (isset($extenssion_ids[$extension]) && $force_reload == false) {
             return $extenssion_ids[$extension];
         }
         $extension_key = $extension;
         Ak::import('Extension');
         $ExtensionInstance =& new Extension();
         $extension =& $ExtensionInstance->findOrCreateBy('name', $extension);
     }
     $extension = is_object($extension) ? $extension->getId() : (empty($extension) ? 'core' : $extension);
     isset($extension_key) ? $extenssion_ids[$extension_key] = $extension : null;
     return $extension;
 }
Esempio n. 30
0
 /**
 * @access private
 */
 function _ensureClassExistsForSerializedColumnBeforeUnserializing($column_name)
 {
     static $imported_cache = array();
     if(empty($imported_cache[$column_name])){
         $class_name = isset($this->serialize[$column_name])  ?
         (is_string($this->serialize[$column_name]) ? $this->serialize[$column_name] : $column_name) : false;
         if($class_name) {
             Ak::import($class_name);
         }
         $imported_cache[$column_name] = true;
     }
 }