function form($objectName, $object, $options = array()) { if (!isset($options['action'])) { if ($object->isNewRecord()) { $options['action'] = 'create'; } else { $options['action'] = 'update'; } } if (!isset($options['submit_value'])) { $options['submit_value'] = ucfirst($options['action']); } if (isset($options['multipart']) && $options['multipart'] === true) { $form = form_tag(array('action' => $options['action']), array('multipart' => true)); } else { $form = form_tag(array('action' => $options['action'])); } if (!$object->isNewRecord()) { $form .= hidden_field($objectName, 'id', $object); } $fields = $object->contentAttributes(); foreach ($fields as $attr) { $form .= '<p><label for="' . $objectName . '_' . $attr->name . '">' . SInflection::humanize($attr->name) . "</label>\n" . input($objectName, $attr->name, $object) . "</p>\n"; } if (isset($options['include'])) { $form .= $options['include']; } $form .= submit_tag($options['submit_value']); $form .= end_form_tag(); return $form; }
public static function getOptions($owner, $name, $options) { if (!is_array($options)) { $type = $options; $options = array(); $options['assoc_type'] = $type; } if (!isset($options['assoc_type'])) { throw new SException('Type of relationship is required.'); } if (!isset($options['class_name'])) { if ($options['assoc_type'] == 'has_many' || $options['assoc_type'] == 'many_to_many') { $options['class_name'] = SInflection::singularize($name); } else { $options['class_name'] = $name; } } $dest = $options['class_name']; // we instanciate the dest class without associations to avoid an infinite loop if (!class_exists($dest)) { SDependencies::requireDependency('models', $dest, get_class($owner)); } $destInstance = new $dest(Null, True); $options['table_name'] = $destInstance->tableName; $options['primary_key'] = $destInstance->identityField; $assocMethod = SInflection::camelize($options['assoc_type']); return self::$assocMethod($owner, $name, $dest, $options); }
public static function requireDependency($layer, $dependency, $relativeTo = null) { list($subdir, $class) = self::dependencySubDir($dependency, $relativeTo); $path = APP_DIR . "/{$layer}/{$subdir}" . SInflection::underscore($class) . '.php'; if (!file_exists($path)) { throw new SException("Missing " . SInflection::singularize($layer) . " {$dependency}"); } require_once $path; }
public function __construct($db, $tableName, $fixturePath, $mode = self::CSV_MODE) { $this->db = $db; $this->mode = $mode; $this->className = ucfirst(SInflection::singularize($tableName)); $this->tableName = $tableName; $this->fixturePath = $fixturePath; $this->readFixtureFile(); }
protected function initialize() { if ($this->scaffold !== null) { $this->models[] = $this->scaffold; if (strpos($this->scaffold, '/') !== false) { list(, $this->scaffold) = explode('/', $this->scaffold); } $this->class_name = SInflection::camelize($this->scaffold); $this->singular_name = strtolower($this->scaffold); $this->plural_name = SInflection::pluralize($this->singular_name); } }
public function __construct($values = Null, $dontInitAssocs = false, $newRecord = True) { if ($this->tableName == Null) { $this->tableName = SInflection::pluralize(strtolower(get_class($this))); } if (empty($this->attributes)) { $this->attributes = SActiveStore::getAttributes($this->tableName); } else { $this->initAttributes(); } $this->initValues(); if ($values != Null && is_array($values)) { $this->populate($values); } $this->newRecord = $newRecord; if (!$dontInitAssocs) { $this->initAssociations(); } }
private function migrationClass($name) { return SInflection::camelize($name); }
private static function controllerClass($reqController) { if (strpos($reqController, '/')) { list(, $controllerName) = explode('/', $reqController); } else { $controllerName = $reqController; } return SInflection::camelize($controllerName) . 'Controller'; }
/** * Returns a radio button tag. * * The radio button will be checked if the current value of <var>$method</var> is * equal to <var>$tagValue</var>. * Example : * <code>radio_button('post', 'title', $this->post, 'Hello World'); * <input id="post_title_hello_world" name="post[title]" type="radio" value="Hello World" /></code> */ function radio_button($objectName, $method, $object, $tagValue, $options = array()) { list($name, $value, $options) = default_options($objectName, $method, $object, $options); $options['id'] .= '_' . SInflection::wikify($tagValue); if ($value == $tagValue) { $checked = True; } else { $checked = False; } return radio_button_tag($name, $tagValue, $checked, $options); }
function testHumanize() { $this->assertEqual('Post', SInflection::humanize('post_id')); $this->assertEqual('Relative post', SInflection::humanize('relative_post_id')); $this->assertEqual('My test', SInflection::humanize('my_test')); }
?> </p> <?php if (count($this->{$this->plural_name}) == 0) { ?> <p>No data.</p> <?php } else { ?> <table> <tr> <?php foreach ($attributes = $this->{$this->plural_name}[0]->contentAttributes() as $attr) { ?> <th><?php echo SInflection::humanize($attr->name); ?> </th> <?php } ?> </tr> <?php for ($i = 0; $i < ($count = count($this->{$this->plural_name})); $i++) { ?> <tr> <?php foreach ($attributes as $attr) { ?> <td><?php echo truncate($this->{$this->plural_name}[$i]->{$attr->name});