function cast() { $this->model_name = AkInflector::camelize($this->model_name); $this->model_file_path = AkInflector::toModelFilename($this->model_name); if (empty($this->actions) && !empty($this->controller_name) && strstr($this->controller_name, ',')) { $this->controller_name = ''; } $this->controller_name = empty($this->controller_name) ? AkInflector::pluralize($this->model_name) : AkInflector::camelize($this->controller_name); $this->controller_file_path = AkInflector::toControllerFilename($this->controller_name); $this->controller_class_name = str_replace(array('/', '::'), '_', $this->controller_name . 'Controller'); $this->controller_name = AkInflector::demodulize($this->controller_name); $this->controller_human_name = AkInflector::humanize($this->controller_name); $this->helper_name = (AkInflector::is_plural($this->controller_name) ? AkInflector::singularize($this->controller_name) : $this->controller_name) . 'Helper'; $this->helper_var_name = '$' . AkInflector::underscore($this->helper_name); $this->singular_name = AkInflector::underscore($this->model_name); $this->plural_name = AkInflector::pluralize($this->singular_name); $this->singular_controller_name = AkInflector::underscore($this->controller_name); $this->module_preffix = AkInflector::underscore(substr($this->controller_class_name, 0, strrpos($this->controller_class_name, '_'))); $this->module_preffix = empty($this->module_preffix) ? '' : DS . $this->module_preffix; $this->files = array('controller.php' => $this->controller_file_path, 'helper.php' => AK_HELPERS_DIR . $this->module_preffix . DS . trim($this->helper_var_name, '$') . '.php', 'layout' => AK_VIEWS_DIR . DS . 'layouts' . DS . $this->singular_controller_name . '.tpl', 'view_add' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'add.tpl', 'view_destroy' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'destroy.tpl', 'view_edit' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'edit.tpl', 'view_listing' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'listing.tpl', 'view_show' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'show.tpl', 'form' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . '_form.tpl'); $this->user_actions = array(); foreach ((array) @$this->actions as $action) { $this->user_actions[$action] = AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . $action . '.tpl'; } }
function Test_of_singularize_plural() { foreach ($this->SingularToPlural as $singular => $plural) { $this->assertEqual($singular, AkInflector::singularize($plural)); $this->assertEqual(ucfirst($singular), AkInflector::singularize(ucfirst($plural))); } }
public function init($options = array()) { $success = $this->_ensureIsActiveRecordInstance($this->_ActiveRecordInstance); $singularized_model_name = AkInflector::underscore(AkInflector::singularize($this->_ActiveRecordInstance->getTableName())); $default_options = array('base_path' => AK_BASE_DIR . DS . 'index' . AK_ENVIRONMENT . DS); $this->options = array_merge($default_options, $options); return $success; }
function _getSingularAttributeName($attribute_name) { $singular_name = AkInflector::singularize($attribute_name); if ($singular_name === $attribute_name) { return false; } return $singular_name; }
function init($options = array()) { $success = $this->_ensureIsActiveRecordInstance($this->_ActiveRecordInstance); $singularized_model_name = AkInflector::underscore(AkInflector::singularize($this->_ActiveRecordInstance->getTableName())); $default_options = array('class_name' => $this->_ActiveRecordInstance->getModelName() . 'IpGeocodeLookup'); $this->options = array_merge($default_options, $options); return $success; }
public function __construct($entities, $options) { $this->plural = $entities; $this->singular = isset($options['singular']) ? $options['singular'] : AkInflector::singularize($this->plural); $this->path_segment = isset($options['singular']) || isset($options['as']) ? Ak::deleteAndGetValue($options, 'as') : $this->plural; $this->options = $options; $this->arrangeActions(); $this->addDefaultActions(); $this->setAllowedActions(); $this->setPrefixes(); }
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; }
function &addAssociated($association_id, $options = array()) { $default_options = array('class_name' => empty($options['class_name']) ? AkInflector::camelize($association_id) : $options['class_name'], 'foreign_key' => empty($options['foreign_key']) ? AkInflector::singularize($this->Owner->getTableName()) . '_id' : $options['foreign_key'], 'remote' => false, 'instantiate' => false, 'conditions' => false, 'include_conditions_when_included' => true, 'order' => false, 'include_order_when_included' => true, 'dependent' => false, 'counter_cache' => false); $options = array_merge($default_options, $options); $options['table_name'] = empty($options['table_name']) ? AkInflector::tableize($options['class_name']) : $options['table_name']; $this->setOptions($association_id, $options); $this->addModel($association_id, new AkAssociatedActiveRecord()); $associated =& $this->getModel($association_id); $this->setAssociatedId($association_id, $associated->getId()); $associated =& $this->_build($association_id, &$associated, false); $this->_saveLoadedHandler($association_id, $associated); if ($options['instantiate']) { $associated =& $this->addModel($association_id, new $options['class_name']($options['foreign_key'] . ' = ' . $this->Owner->quotedId())); } return $associated; }
private function _setDefaults() { $this->class_name = AkInflector::camelize($this->class_name); $this->table_name = AkInflector::tableize($this->class_name); $this->file_name = AkInflector::underscore($this->class_name); $this->controller_class_name = AkInflector::pluralize($this->class_name); $this->controller_file_name = AkInflector::toControllerFilename($this->controller_class_name); $this->table_columns = trim(join(' ', (array) @$this->table_columns)); $this->assignVarToTemplate('attributes', $this->_getModelAttributesForViews()); $this->assignVarToTemplate('class_name', $this->class_name); $this->assignVarToTemplate('table_name', $this->table_name); $this->assignVarToTemplate('plural_name', $this->table_name); $this->assignVarToTemplate('singular_name', AkInflector::singularize($this->table_name)); $this->assignVarToTemplate('file_name', $this->file_name); $this->assignVarToTemplate('table_columns', $this->table_columns); $this->assignVarToTemplate('controller_class_name', $this->controller_class_name); }
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); }
function init($options = array()) { $success = $this->_ensureIsActiveRecordInstance($this->_ActiveRecordInstance); $singularized_model_name = AkInflector::underscore(AkInflector::singularize($this->_ActiveRecordInstance->getTableName())); $default_options = array('class_name' => $this->_ActiveRecordInstance->getModelName() . 'ActsAsMappable'); $this->distance_column_name = array_key_exists('distance_column_name', $options) ? $options['distance_column_name'] : 'distance'; $this->default_units = array_key_exists('default_units', $options) ? $options['default_units'] : GEOKIT_DEFAULT_UNITS; $this->default_foumula = array_key_exists('default_formula', $options) ? $options['default_formula'] : GEOKIT_DEFAULT_FORMULA; $this->lat_column_name = array_key_exists('lat_column_name', $options) ? $options['lat_column_name'] : 'lat'; $this->lng_column_name = array_key_exists('lng_column_name', $options) ? $options['lng_column_name'] : 'lng'; $this->qualified_lat_column_name = $this->table_name . $this->lat_column_name; $this->qualified_lng_column_name = $this->table_name . $this->lng_column_name; if (array_key_exists('auto_geocode', $options)) { if ($options['auto_geocode'] == true) { $options['auto_geocode'] = array(); } $this->auto_geocode_field = array_key_exists('field', $options['auto_geocode']) ? $options['auto_geocode']['field'] : 'address'; $this->auto_geocode_error_message = array_key_exists('error_message', $options['auto_geocode']) ? $options['auto_geocode']['error_message'] : 'could not locate address'; } $this->options = array_merge($default_options, $options); return $success; }
function init($options = array()) { $success = $this->_ensureIsActiveRecordInstance($this->_ActiveRecordInstance); $singularized_model_name = AkInflector::underscore(AkInflector::singularize($this->_ActiveRecordInstance->getTableName())); $default_options = array( 'class_name' => $this->_ActiveRecordInstance->getModelName().'Version', 'table_name' => $singularized_model_name.'_versions', 'foreign_key' => $singularized_model_name.'_id', 'inheritance_column' => 'versioned_type', 'version_column' => 'version', 'limit' => false, 'if' => true, 'if_changed' => array(), 'ignored_columns' => array('updated_at'), ); $this->options = array_merge($default_options, $options); $this->_ensureVersioningModelIsAvailable(); return $success; }
function Loop($match, $state) { if(AK_LEXER_SPECIAL === $state){ $sintags_var = trim(preg_replace('/[\s|?]+/',' ', substr($match, 6,-1))); if(strstr($sintags_var,' as ')){ $new_sintags_var = substr($sintags_var,0, strpos($sintags_var,' ')); $termination = $this->_getTerminationName(AkInflector::pluralize(str_replace($new_sintags_var.' as ','', $sintags_var))); $sintags_var = $new_sintags_var; } $php_variable = $this->_convertSintagsVarToPhp($sintags_var); if($php_variable){ $php_variable = $php_variable; $termination = empty($termination) ? $this->_getTerminationName($sintags_var) : $termination; $singular_variable = '$'.AkInflector::singularize($termination); $plural_variable = '$'.$termination; $this->output .= "<?php ". "\n empty({$php_variable}) ? null : {$singular_variable}_loop_counter = 0;". "\n empty({$php_variable}) ? null : {$plural_variable}_available = count({$php_variable});". "\n if(!empty({$php_variable}))". "\n foreach ({$php_variable} as {$singular_variable}_loop_key=>{$singular_variable}){". "\n {$singular_variable}_loop_counter++;". "\n {$singular_variable}_is_first = {$singular_variable}_loop_counter === 1;". "\n {$singular_variable}_is_last = {$singular_variable}_loop_counter === {$plural_variable}_available;". "\n {$singular_variable}_odd_position = {$singular_variable}_loop_counter%2;". "\n?>"; }else{ $this->output .= $match; } } return true; }
function modulize($module_description) { return AkInflector::camelize(AkInflector::singularize($module_description)); }
function getCollectionHandlerName($association_id) { if (isset($this->{$association_id}) && is_object($this->{$association_id}) && method_exists($this->{$association_id}, 'getAssociatedFinderSqlOptions')) { return false; } $collection_handler_name = AkInflector::singularize($association_id); if (isset($this->{$collection_handler_name}) && is_object($this->{$collection_handler_name}) && in_array($this->{$collection_handler_name}->getType(), array('hasMany', 'hasAndBelongsToMany'))) { return $collection_handler_name; } else { return false; } }
function &addAssociated($association_id, $options = array()) { $default_options = array('class_name' => empty($options['class_name']) ? AkInflector::modulize($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' => 'AkActiveRecord', '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); $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', 'modulize'), 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() ? null : trigger_error(Ak::t('Could find join model %model_name for hasAndBelongsToMany association %id', array('%table_name' => $options['join_class_name'], 'id' => $this->association_id)), E_USER_ERROR); return $Collection; }
public function test_spanish_dictionary() { $this->assertNotEqual('tijeras',AkInflector::singularize('tijeras')); $this->assertEqual('tijeras',AkInflector::singularize('tijeras',null,'es')); $this->assertEqual('ingleses',AkInflector::pluralize('inglés',null,'es')); }
function _paginationValidateOptions($collection_id, $options = array(), $in_action) { $this->_pagination_options = array_merge($this->_pagination_default_options, $this->_pagination_options); $valid_options = array_keys($this->_pagination_default_options); $valid_options = !in_array($in_action, $valid_options) ? array_merge($valid_options, $this->_pagination_actions) : $valid_options; $unknown_option_keys = array_diff(array_keys($this->_pagination_options), $valid_options); if (!empty($unknown_option_keys)) { trigger_error(Ak::t('Unknown options for pagination: %unknown_option', array('%unknown_option' => join(', ', $unknown_option_keys))), E_USER_WARNING); } $this->_pagination_options['singular_name'] = !empty($this->_pagination_options['singular_name']) ? $this->_pagination_options['singular_name'] : AkInflector::singularize($collection_id); $this->_pagination_options['class_name'] = !empty($this->_pagination_options['class_name']) ? $this->_pagination_options['class_name'] : AkInflector::camelize($this->_pagination_options['singular_name']); }
public function quantify($item) { if ($this->value == 1) { return $this->value . ' ' . Ak::t(AkInflector::singularize($item)); } else { return $this->value . ' ' . Ak::t(AkInflector::pluralize($item)); } }
function _getSingularVariableNameForLoop($plural) { return '$' . AkInflector::singularize(substr($plural, max(strpos($plural, '.'), strpos($plural, '-'), -1) + 1)); }
function Test_for_setting_custom_singulars() { AkInflector::singularize('camiones', 'camión'); $this->assertEqual(AkInflector::singularize('camiones'), 'camión'); }
public function singularize($dictionary = null) { return AkInflector::singularize($this->value, null, $dictionary); }
public function assertSingletonResourceAllowedRoutes($controller, $options, $allowed, $not_allowed, $path = null) { $path = empty($path) ? AkInflector::singularize($controller) : $path; $format = isset($options['format']) ? '.' . $options['format'] : ''; $options = array_merge(array('controller' => $controller), $options); $this->assertWhetherAllowed($allowed, $not_allowed, $options, 'add', $path . '/add' . $format, 'get'); $this->assertWhetherAllowed($allowed, $not_allowed, $options, 'create', $path . $format, 'post'); $this->assertWhetherAllowed($allowed, $not_allowed, $options, 'show', $path . $format, 'get'); $this->assertWhetherAllowed($allowed, $not_allowed, $options, 'edit', $path . '/edit' . $format, 'get'); $this->assertWhetherAllowed($allowed, $not_allowed, $options, 'update', $path . $format, 'put'); $this->assertWhetherAllowed($allowed, $not_allowed, $options, 'destroy', $path . $format, 'delete'); }
static function is_plural($plural) { return AkInflector::pluralize(AkInflector::singularize($plural)) == $plural; }
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; }