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; }
public function testClassMethod() { $this->assertEquals('myClassMethod', StringFormat::classMethod('myClassMethod')); $this->assertEquals('myClassMethod', StringFormat::classMethod('my-class-Method')); $this->assertEquals('myClassMethod', StringFormat::classMethod('my Class Method')); $this->assertEquals('myClassMethod', StringFormat::classMethod('my %^&* Class Method')); $this->assertEquals('myClassMethod', StringFormat::classMethod('my____Class Method')); $this->assertEquals('myClassMethod', StringFormat::classMethod('my/Class Method')); }
function getTemplateParams($table_name) { $class_name = $this->getModelName($table_name); $column_names = $PKs = array(); $auto_increment = false; $columns = $this->getColumns($table_name); $pks = $this->getPrimaryKeys($table_name); $pk = null; foreach ($columns as &$column) { $column_names[] = $column->getName(); if ($column->isPrimaryKey()) { $PKs[] = $column->getName(); if ($column->isAutoIncrement()) { $auto_increment = true; } } } if (count($PKs) == 1) { $pk = $PKs[0]; } else { $auto_increment = false; } return array('auto_increment' => $auto_increment, 'table_name' => $table_name, 'controller_name' => $this->getControllerName($table_name), 'model_name' => $class_name, 'column_names' => $column_names, 'plural' => StringFormat::pluralVariable($table_name), 'plural_url' => StringFormat::pluralURL($table_name), 'single' => StringFormat::variable($table_name), 'single_url' => StringFormat::url($table_name), 'pk' => $pk, 'primary_keys' => $pks, 'pk_method' => $pk ? StringFormat::classMethod('get' . StringFormat::titleCase($pk)) : null, 'pk_var' => $pk ? StringFormat::variable($pk) : null, 'actions' => $this->getActions($table_name), 'columns' => $columns); }