本文整理匯總了PHP中Inflector::plural方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::plural方法的具體用法?PHP Inflector::plural怎麽用?PHP Inflector::plural使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Inflector
的用法示例。
在下文中一共展示了Inflector::plural方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: initialize
/**
* Initialize object (for relations)
* @param orm $object
*/
public function initialize(&$object)
{
$models[0] = Inflector::plural(strtolower(str_replace('Model_', '', get_class($object))));
$models[1] = $this->item['name'];
sort($models);
$object->create_relation('hasMany', $this->item['name'], array('model' => Inflector::singular($this->item['name']), 'through' => $models[0] . '_' . $models[1]));
}
示例2: initialize
/**
* Automatically sets foreign to sensible defaults.
*
* @param string $model
* @param string $name
* @return void
*/
public function initialize(Jam_Meta $meta, $name)
{
parent::initialize($meta, $name);
if (!$this->foreign_key) {
$this->foreign_key = $name . '_id';
}
if ($this->foreign_key === $name) {
throw new Kohana_Exception('In association ":name" for model ":model" - invalid foreign_key name. Field and Association cannot be the same name', array(':model' => $this->model, ':name' => $name));
}
$meta->field($this->foreign_key, Jam::field('integer', array_merge($this->_default_field_options, $this->field_options)));
if ($this->is_polymorphic()) {
if (!is_string($this->polymorphic)) {
$this->polymorphic = $name . '_model';
}
$meta->field($this->polymorphic, Jam::field('string', array('convert_empty' => TRUE)));
} elseif (!$this->foreign_model) {
$this->foreign_model = $name;
}
if ($this->count_cache) {
if ($this->is_polymorphic()) {
throw new Kohana_Exception('Cannot use count cache on polymorphic associations');
}
if ($this->count_cache === TRUE) {
$this->count_cache = Inflector::plural($this->model) . '_count';
}
}
}
示例3: __construct
function __construct(Jam_Query_Builder_Collection $collection, $offset, array $columns = array())
{
$this->collection($collection);
$this->controller(Inflector::plural($collection->meta()->model()));
$this->columns($columns);
$this->_offset = $offset;
}
示例4: submit
protected function submit($task, $id, $type)
{
$item = Jelly::select($type, $id);
$redirect = HTML::uri(array('action' => Inflector::plural($type)));
switch ($task) {
case 'apply':
$item->set($_POST)->save();
$redirect = HTML::uri(array('action' => $type, 'task' => 'edit', 'id' => $item->id));
$this->request->redirect($redirect);
break;
case 'save':
$item->set($_POST)->save();
$this->request->redirect($redirect);
break;
case 'cancel':
$this->request->redirect($redirect);
break;
case 'delete':
if ($ids = Arr::get($_POST, 'cid', NULL)) {
$items = Jelly::delete($item)->where(':primary_key', 'IN', $ids)->execute();
}
$this->request->redirect($redirect);
break;
case 'default':
if (!$item->loaded()) {
$this->request->redirect($redirect);
}
break;
}
return $item;
}
示例5: action_calendar
public function action_calendar()
{
$view = View::factory('calendar/calendar')->bind('calendar', $calendar_markup);
$month = Arr::get($_GET, 'month', date('m'));
$year = Arr::get($_GET, 'year', date('Y'));
$event_type = Arr::get($_GET, 'event_type');
$calendar = new Calendar($month, $year);
$calendar->standard('prev-next');
$event = Model_Event::monthly_events($month, $year, $event_type);
$day_events = array();
// loop though events and group events by day and event types
foreach ($event as $e) {
$day = date('j-m', $e->eventstart);
if (!isset($day_events[$day][$e->eventtype])) {
$day_events[$day][$e->eventtype] = array();
}
$day_events[$day][$e->eventtype][] = array('id' => $e->id);
}
if ($day_events) {
foreach ($day_events as $daymonth => $types) {
list($day, $month) = explode("-", $daymonth);
$timestamp = mktime(0, 0, 0, $month, (int) $day, $year);
foreach ($types as $type => $events) {
$count = count($events);
$type = $count > 1 ? Inflector::plural($type) : $type;
$calendar->attach($calendar->event()->condition('timestamp', (int) $timestamp)->output($count . ' ' . $type));
}
}
}
$calendar->attach($calendar->event()->condition('timestamp', time())->add_class('today'));
$calendar_markup = $calendar->render();
$this->content = $view;
}
示例6: name
/**
* Return the item's name prefixed with its amount
*
* @return string
*/
public function name()
{
if ($this->amount > 1) {
return $this->amount . ' ' . Inflector::plural($this->item->name, $this->amount);
} else {
return $this->amount . ' ' . $this->item->name;
}
}
示例7: initialize
public function initialize(Jam_Meta $meta, $name)
{
parent::initialize($meta, $name);
if (!$this->_branches_table) {
$this->_branches_table = ($meta->table() ?: Inflector::plural($meta->model())) . '_branches';
}
$meta->associations(array('parent' => Jam::association('closuretable_parent', array('foreign_model' => $this->_model, 'branches_table' => $this->_branches_table, 'ansestor_key' => $this->_ansestor_key, 'descendant_key' => $this->_descendant_key, 'depth_key' => $this->_depth_key, 'inverse_of' => 'children')), 'children' => Jam::association('closuretable_children', array('foreign_model' => $this->_model, 'branches_table' => $this->_branches_table, 'ansestor_key' => $this->_ansestor_key, 'descendant_key' => $this->_descendant_key, 'depth_key' => $this->_depth_key, 'inverse_of' => 'parent', 'children_dependent' => $this->_children_dependent))));
$meta->events()->bind('model.after_save', array($this, 'model_before_after_save'), Jam_Event::ATTRIBUTE_PRIORITY + 1);
}
示例8: apply
public function apply($collection)
{
if (!$this->controller()) {
$this->controller(Inflector::plural($collection->meta()->model()));
}
foreach ($this->data() as $name => $value) {
if ($value and $this->entries($name)) {
$this->entries($name)->apply($collection, $value);
}
}
return $this;
}
示例9: add_validator
/**
* Add a validator item
*
* @access public
* @param mixed $type
* @param mixed $rule
* @return object
*/
public function add_validator($type, $rule)
{
$type = Inflector::plural($rule->type);
if (in_array($type, array('filters', 'display_filters'))) {
return $this->add_filter(Inflector::singular($type), $rule);
}
$next = count($this->_validators[$type]);
// Resolve the context
$this->make_context($rule);
$this->_validators[$type][$next] = $rule;
return $this;
}
示例10: build
public function build($model, array $values = NULL)
{
$column = Inflector::plural($model);
$col = Arr::get($this->_has_many, $column);
$foreign_key = Arr::get($col, 'foreign_key');
$polymorphic = Arr::get($col, 'polymorphic', FALSE);
$object = ORM::factory($model);
if ($polymorphic && $object instanceof ORM_Polymorph) {
$foreign_key = $object->polymorph_id();
$foreign_type = $object->polymorph_type();
$values[$foreign_type] = $this->object_name();
}
$values[$foreign_key] = $this->id;
return $object->values($values);
}
示例11: render_menu
function render_menu($items, $parent = NULL)
{
$html = '';
$ignored = array();
foreach ($items as $item) {
$controller_name = 'Controller_Manager_' . $item;
if (class_exists($controller_name)) {
$reflector = new ReflectionClass($controller_name);
if ($reflector->isAbstract()) {
continue;
}
}
if (in_array($item, $ignored)) {
continue;
}
$matches = preg_grep('/^' . $item . '_/i', $items);
if ($matches and !$parent) {
$html .= '<li><a href="#" class="dropdown-toggle" data-toggle="dropdown">';
$html .= __(Inflector::plural($item)) . ' <span class="caret"></span>';
$html .= '</a>';
$html .= '<ul class="dropdown-menu">';
if (Can::show($item, 'index')) {
$html .= '<li><a href="./manager/' . strtolower($item) . '">' . __(Inflector::plural($item)) . '</a></li>';
}
$html .= render_menu($matches, $item);
$html .= '</ul></li>';
$ignored = array_merge($ignored, $matches);
} else {
if (!Can::show($item, 'index')) {
continue;
}
$prepend = '';
if ($parent) {
$underlines = count(explode('_', $item));
if ($underlines >= 3) {
for ($i = $underlines; $i > 3; $i--) {
$prepend .= '<i class="glyphicon glyphicon-option-horizontal"></i>';
}
$prepend .= '<i class="glyphicon glyphicon-triangle-right"></i>';
}
}
$html .= '<li><a href="./manager/' . strtolower($item) . '">' . $prepend . __(Inflector::plural($item)) . '</a></li>';
}
}
return $html;
}
示例12: add
public function add($alias, $driver = NULL, $value = NULL, array $options = NULL)
{
// If Formo object was passed, add it as a subform
if ($driver instanceof Formo) {
return $this->add_subform($driver);
}
if ($alias instanceof Formo) {
return $this->add_subform($alias->alias($driver));
}
if ($value instanceof Formo) {
return $this->add_subform($value->alias($alias)->set('driver', $driver));
}
$orig_options = $options;
$options = func_get_args();
$options = self::args(__CLASS__, __FUNCTION__, $options);
// If a driver is named but not an alias, make the driver text and the alias the driver
if (empty($options['driver'])) {
$options['driver'] = Arr::get($this->config, 'default_driver', 'text');
}
// Allow loading rules, callbacks, filters upon adding a field
$validate_options = array('rule', 'trigger', 'filter');
// Create the array
$validate_settings = array();
foreach ($validate_options as $option) {
$option_name = Inflector::plural($option);
if (!empty($options[$option_name])) {
$validate_settings[$option] = $options[$option_name];
unset($options[$option_name]);
}
}
// Create the new field
$field = Ffield::factory($options);
$this->append($field);
// Add the validation rules
foreach ($validate_settings as $method => $array) {
foreach ($array as $callback => $opts) {
$args = array(NULL, $callback, $opts);
call_user_func_array(array($field, $method), $args);
}
}
return $this;
}
示例13: time_since
/**
* Returns the time since a particular time
*
* @static
*
* @param $i_datetime1
* @param null $i_datetime2
*
* @return string
*
* @author Marcel Beck <marcel.beck@outlook.com>
*/
public static function time_since($i_datetime1, $i_datetime2 = null)
{
$datetime1 = new \DateTime($i_datetime1);
$datetime2 = $i_datetime2 === null ? new \DateTime('now') : new \DateTime($i_datetime2);
$interval = $datetime1->diff($datetime2);
$doPlural = function ($nb, $str) {
return $nb > 1 ? Inflector::plural($str) : $str;
};
// adds plurals
$format = array();
if ($interval->y !== 0) {
$format[] = '%y ' . $doPlural($interval->y, __('year'));
}
if ($interval->m !== 0) {
$format[] = '%m ' . $doPlural($interval->m, _('month'));
}
if ($interval->d !== 0) {
$format[] = '%d ' . $doPlural($interval->d, _('day'));
}
if ($interval->h !== 0) {
$format[] = '%h ' . $doPlural($interval->h, __('hour'));
}
if ($interval->i !== 0) {
$format[] = '%i ' . $doPlural($interval->i, __('minute'));
}
if ($interval->s !== 0) {
if (!count($format)) {
return __('less than a minute ago');
} else {
$format[] = '%s ' . $doPlural($interval->s, __('second'));
}
}
// We use the two biggest parts
if (count($format) > 1) {
$format = array_shift($format) . ' ' . __('and') . ' ' . array_shift($format);
} else {
$format = array_pop($format);
}
//echo $interval->format('%y years, %m months, %d days, %h hours and %i minutes ago');
return $interval->format($format);
}
示例14: finalize
/**
* This is called after initialization to
* finalize any changes to the meta object.
*
* @param string $model
* @return
*/
public function finalize($model)
{
if ($this->_initialized) {
return;
}
// Set the name of a possible behavior class
$behavior_class = Jam::behavior_prefix() . Jam::capitalize_class_name($model);
// See if we have a special behavior class to use
if (class_exists($behavior_class)) {
// Load behavior
$behavior = new $behavior_class();
if (!in_array($behavior, $this->_behaviors)) {
// Add to behaviors
$this->_behaviors[] = $behavior;
}
}
foreach ($this->_behaviors as $name => $behavior) {
if (!$behavior instanceof Jam_Behavior) {
throw new Kohana_Exception('Behavior at index [ :key ] is not an instance of Jam_Behavior, :type found.', array(':type' => is_object($behavior) ? 'instance of ' . get_class($behavior) : gettype($behavior), ':key' => $name));
}
// Initialize behavior
$behavior->initialize($this, $name);
}
// Allow modification of this meta object by the behaviors
$this->_events->trigger('meta.before_finalize', $this);
// Ensure certain fields are not overridden
$this->_model = $model;
$this->_defaults = array();
if (!$this->_errors_filename) {
// Default errors filename to the model's name
$this->_errors_filename = 'validators/' . $this->_model;
}
// Table should be a sensible default
if (empty($this->_table)) {
$this->_table = Inflector::plural($model);
}
// Can we set a sensible foreign key?
if (empty($this->_foreign_key)) {
$this->_foreign_key = $model . '_id';
}
if (empty($this->_unique_key) and method_exists(Jam::class_name($this->_model), 'unique_key')) {
$this->_unique_key = Jam::class_name($this->_model) . '::unique_key';
}
foreach ($this->_fields as $column => $field) {
// Ensure a default primary key is set
if ($field instanceof Jam_Field and $field->primary and empty($this->_primary_key)) {
$this->_primary_key = $column;
}
// Ensure a default plymorphic key is set
if ($field instanceof Jam_Field_Polymorphic and empty($this->_polymorphic_key)) {
$this->_polymorphic_key = $column;
}
}
foreach ($this->_associations as $column => &$association) {
$association->initialize($this, $column);
}
foreach ($this->_fields as $column => &$field) {
$field->initialize($this, $column);
$this->_defaults[$column] = $field->default;
}
if (!$this->_collection and $class = Jam::collection_prefix() . Jam::capitalize_class_name($this->_model) and class_exists($class)) {
$this->_collection = $class;
}
// Meta object is initialized and no longer writable
$this->_initialized = TRUE;
// Final meta callback
$this->_events->trigger('meta.after_finalize', $this);
}
示例15: _initialize
/**
* Prepares the model database connection, determines the table name,
* and loads column information.
*
* @return void
*/
protected function _initialize()
{
if (!is_object($this->_db)) {
// Get database instance
$this->_db = Database::instance($this->_db);
}
if (empty($this->_table_name)) {
// Table name is the same as the object name
$this->_table_name = $this->_object_name;
if ($this->_table_names_plural === TRUE) {
// Make the table name plural
$this->_table_name = Inflector::plural($this->_table_name);
}
}
foreach ($this->_belongs_to as $alias => $details) {
$defaults['model'] = $alias;
$defaults['foreign_key'] = $alias . $this->_foreign_key_suffix;
$this->_belongs_to[$alias] = array_merge($defaults, $details);
}
foreach ($this->_has_one as $alias => $details) {
$defaults['model'] = $alias;
$defaults['foreign_key'] = $this->_object_name . $this->_foreign_key_suffix;
$this->_has_one[$alias] = array_merge($defaults, $details);
}
foreach ($this->_has_many as $alias => $details) {
$defaults['model'] = Inflector::singular($alias);
$defaults['foreign_key'] = $this->_object_name . $this->_foreign_key_suffix;
$defaults['through'] = NULL;
$defaults['far_key'] = Inflector::singular($alias) . $this->_foreign_key_suffix;
$this->_has_many[$alias] = array_merge($defaults, $details);
}
// Load column information
$this->reload_columns();
}