function getActions($table_name) { $single = StringFormat::variable($table_name); $pks = $this->getPrimaryKeys($table_name); if (count($pks) === 1) { $pk = $pks[0]; } else { $pk = null; } $actions = array(); if (!$pk) { return $actions; } $pk_method = StringFormat::classMethod('get' . StringFormat::titleCase($pk->getName())); foreach ($this->standardActions as &$staction) { $actions[$staction] = "<?php echo site_url('" . StringFormat::pluralURL($table_name) . '/' . strtolower($staction) . "/' . \$" . $single . '->' . $pk_method . '()) ?>'; } $fkeys_to = $this->getForeignKeysToTable($table_name); foreach ($fkeys_to as $k => &$r) { $from_table = $r->getTableName(); $local_columns = $r->getLocalColumns(); $from_column = array_shift($local_columns); if (@$used_to[$from_table]) { unset($fkeys_to[$k]); continue; } $used_to[$from_table] = $from_column; $actions[ucwords(StringFormat::titleCase(StringFormat::plural($from_table), ' '))] = "<?php echo site_url('" . StringFormat::pluralURL($from_table) . "?{$from_column}=' . \$" . $single . '->' . $pk_method . '()) ?>'; } return $actions; }
/** * Throws UnexpectedValueException if the row class, either gleaned from Query::getTable() or * provided directly, does not exist. * Throws UnexpectedValueException if the above class does not have Model in its ancestry. * * @param Query $query * @param string $class = null */ public function __construct(Query $query, $class = null) { if ($class) { $this->class = trim($class); } else { $this->class = trim(StringFormat::className($query->getTable())); } if (!class_exists($this->class)) { throw new UnexpectedValueException(sprintf('Class "%s" does not exist.', $this->class)); } if (!is_a($this->class, 'Model', true)) { throw new UnexpectedValueException(sprintf('Class "%s" does not inherit from Model.', $this->class)); } $this->query = $query; }
/** * @param Query $q * @param int $limit * @param int $page * @param string $class_name */ function __construct(Query $q, $limit = null, $page = null, $class_name = null, $select_method_name = 'doSelect') { $this->setQuery($q); if ($class_name) { $this->setClass($class_name); } elseif (func_num_args() < 4 && ($table = $q->getTable()) && !$table instanceof Query) { $table_parts = explode('.', $table); $table_name = array_pop($table_parts); $this->setClass(StringFormat::className($table_name)); } if ($select_method_name) { $this->setMethod($select_method_name); } $this->setLimit($limit); $this->setPageNum($page); }
function __construct(ControllerRoute $route = null) { parent::__construct($route); $this['title'] = 'Site Title'; $this['actions'] = array('Home' => site_url()); $current_controller = str_replace('Controller', '', get_class($this)); if ('Index' == $current_controller) { $this['current_page'] = 'Home'; } else { $this['current_page'] = StringFormat::titleCase($current_controller, ' '); } foreach (glob(CONTROLLERS_DIR . '*.php') as $controller_file) { $controller = str_replace('Controller.php', '', basename($controller_file)); if ($controller == 'Application' || $controller == 'Index') { continue; } $this['actions'][StringFormat::titleCase($controller, ' ')] = site_url(StringFormat::url($controller)); } }
echo StringFormat::titleCase($from_column); ?> */ <?php $used_methods[] = 'count' . StringFormat::titleCase($from_class_name) . 's'; ?> function count<?php echo StringFormat::titleCase($from_class_name); ?> s(Query $q = null) { return $this->count<?php echo StringFormat::titleCase($from_class_name); ?> sRelatedBy<?php echo StringFormat::titleCase($from_column); ?> ($q); } <?php } } ?> /** * Returns true if the column values validate. * @return bool */ function validate() { $this->_validationErrors = array(); <?php
/** * @param string $table_name * @return string */ function getControllerName($table_name) { $controller_name = StringFormat::plural($table_name); return StringFormat::className($controller_name) . 'Controller'; }
$output = '<?php echo h($' . $single . '->' . $method . '(' . $format . ')) ?>'; $label = $column_name; if ($column->isForeignKey()) { $fks = $column->getForeignKeys(); $fk = reset($fks); $foreign_table_name = $fk->getForeignTableName(); $label = ucfirst($foreign_table_name); $fk_single = strtolower($foreign_table_name); $fk_columns = $fk->getForeignColumns(); $foreign_column_name = reset($fk_columns); $foreign_column_method = 'get' . StringFormat::titleCase($foreign_column_name); $foreign_open_foreach = '<?php foreach (' . $this->getModelName($foreign_table_name) . '::doSelect() as $' . $fk_single . '): ?>'; $foreign_option = '<option <?php if ($' . $single . '->get' . StringFormat::titleCase($column_name) . '() === $' . $fk_single . '->' . $foreign_column_method . '()) echo \'selected="selected"\' ?> value="<?php echo $' . $fk_single . '->' . $foreign_column_method . '() ?>"><?php echo $' . $fk_single . '?></option>'; $foreign_close_foreach = '<?php endforeach ?>'; } $label = StringFormat::titleCase($label, ' '); $input_id = strtolower($single . '_' . $column_name); ?> <div class="form-field-wrapper"> <label class="form-field-label" for="<?php echo $input_id; ?> "><?php echo $label; ?> </label> <?php switch ($column->getType()) { case Model::COLUMN_TYPE_BOOLEAN: ?> <label>
} if (null === $value && is_array($column) && Model::isTemporalType($type)) { $column = <?php echo $model_name; ?> ::coerceTemporalValue($column, $type); } return parent::addOr($column, $value, $operator, $quote); } <?php foreach ($columns as $key => &$column) { $constant = $model_name . '::' . StringFormat::constant($column->getName()); $php_name = StringFormat::titleCase($column->getName()); $column_type = $model_name . '::COLUMN_TYPE_' . $column->getType(); $value_param = '$' . StringFormat::variable($column->getType()); foreach (array('and', 'or') as $verb) { foreach (array('', 'Not', 'Like', 'NotLike', 'Greater', 'GreaterEqual', 'Less', 'LessEqual', 'Null', 'NotNull', 'Between', 'BeginsWith', 'EndsWith', 'Contains') as $oper) { switch ($oper) { case 'Null': case 'NotNull': $params = ''; break; case 'Between': $params = $value_param . ', $from, $to'; break; default: $params = $value_param; break; } ?>
echo "<?php echo site_url('" . $plural_url . "/edit') ?>"; ?> " class="button" data-icon="plusthick" title="New <?php echo str_replace('_', ' ', ucfirst($single)); ?> "> New <?php echo str_replace('_', ' ', ucfirst($single)); ?> </a> <?php echo StringFormat::titleCase($plural, ' '); ?> </h1> <?php echo "<?php View::load('pager', compact('pager')) ?>"; ?> <div class="ui-widget-content ui-corner-all"> <?php echo "<?php View::load('" . $plural_url . "/grid', \$params) ?>"; ?> </div>
case Model::COLUMN_TYPE_INTEGER_TIMESTAMP: $format = 'VIEW_TIMESTAMP_FORMAT'; break; case Model::COLUMN_TYPE_DATE: $format = 'VIEW_DATE_FORMAT'; break; default: $format = null; break; } if ($column->isForeignKey()) { $col_fks = $column->getForeignKeys(); $fk = array_shift($col_fks); $foreign_table = $fk->getForeignTableName(); $local_column = $fk->getLocalColumnName(); $long_method = 'get' . StringFormat::titleCase("{$foreign_table}_related_by_{$local_column}", ''); $output = '<?php echo h($' . $single . '->' . "{$long_method}" . '()) ?>'; } elseif ($column->getType() == Model::COLUMN_TYPE_BOOLEAN) { $output = '<?php if ($' . $single . '->' . "get{$column_name}" . '(' . $format . ') === 1) echo \'Yes\'; elseif ($' . $single . '->' . "get{$column_name}" . '(' . $format . ') === 0) echo \'No\' ?>'; } else { $output = '<?php echo h($' . $single . '->' . "get{$column_name}" . '(' . $format . ')) ?>'; } ?> <div class="field-wrapper"> <span class="field-label"><?php echo $column_label; ?> </span> <?php echo $output; ?>
public function testPlural() { $this->assertEquals('test-cases', StringFormat::plural('test-case')); $this->assertEquals('x-men', StringFormat::plural('x-man')); $this->assertEquals('test-quizzes', StringFormat::plural('test-quiz')); $this->assertEquals('test-oxen', StringFormat::plural('test-ox')); $this->assertEquals('test-mice', StringFormat::plural('test-mouse')); $this->assertEquals('test-vertices', StringFormat::plural('test-vertex')); $this->assertEquals('test-messes', StringFormat::plural('test-mess')); $this->assertEquals('test-maxes', StringFormat::plural('test-max')); $this->assertEquals('test-marties', StringFormat::plural('test-marty')); $this->assertEquals('test hives', StringFormat::plural('test hive')); $this->assertEquals('test halves', StringFormat::plural('test half')); $this->assertEquals('test calves', StringFormat::plural('test calf')); $this->assertEquals('test crises', StringFormat::plural('test crisis')); $this->assertEquals('test titania', StringFormat::plural('test titanium')); $this->assertEquals('test tomotatos', StringFormat::plural('test tomotato')); // array('/(bu)s$/i', "$1ses"), // array('/(alias|status|campus)$/i', "$1es"), // array('/(octop|cact|vir)us$/i', "$1i"), // array('/(ax|test)is$/i', "$1es"), // array('/^(m|wom)an$/i', "$1en"), // array('/(child)$/i', "$1ren"), // array('/(p)erson$/i', "$1eople"), // array('/s$/i', "s"), // array('/$/', "s") }