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; }
/** * @param string $table_name * @return string */ function getControllerName($table_name) { $controller_name = StringFormat::plural($table_name); return StringFormat::className($controller_name) . 'Controller'; }
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") }