本文整理汇总了PHP中inflector::plural方法的典型用法代码示例。如果您正苦于以下问题:PHP inflector::plural方法的具体用法?PHP inflector::plural怎么用?PHP inflector::plural使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inflector
的用法示例。
在下文中一共展示了inflector::plural方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Sets up foreign and through properly.
*
* @param string $model
* @param string $column
* @return void
*/
public function initialize($model, $column)
{
// Default to the name of the column
if (empty($this->foreign)) {
$foreign_model = inflector::singular($column);
$this->foreign = $foreign_model . '.' . $foreign_model . ':primary_key';
} elseif (is_string($this->foreign) and FALSE === strpos($this->foreign, '.')) {
$this->foreign = $this->foreign . '.' . $this->foreign . ':primary_key';
}
// Create an array from them for easier access
if (!is_array($this->foreign)) {
$this->foreign = array_combine(array('model', 'field'), explode('.', $this->foreign));
}
// Create the default through connection
if (empty($this->through) or is_string($this->through)) {
if (empty($this->through)) {
// Find the join table based on the two model names pluralized,
// sorted alphabetically and with an underscore separating them
$through = array(inflector::plural($this->foreign['model']), inflector::plural($model));
sort($through);
$this->through = implode('_', $through);
}
$this->through = array('model' => $this->through, 'fields' => array(inflector::singular($model) . ':foreign_key', inflector::singular($this->foreign['model']) . ':foreign_key'));
}
parent::initialize($model, $column);
}
示例2: initialize
/**
* Overrides the initialize to automatically provide the column name
*
* @param string $model
* @param string $column
* @return void
*/
public function initialize($model, $column)
{
// Default to the name of the column
if (empty($this->foreign)) {
$foreign_model = inflector::singular($column);
$this->foreign = $foreign_model . '.' . $foreign_model . ':primary_key';
} elseif (FALSE === strpos($this->foreign, '.')) {
$this->foreign = $this->foreign . '.' . $this->foreign . ':primary_key';
}
// Split them apart
$foreign = explode('.', $this->foreign);
// Create an array from them
$this->foreign = array('model' => $foreign[0], 'column' => $foreign[1]);
// We can work with nothing passed or just a model
if (empty($this->through) or is_string($this->through)) {
if (empty($this->through)) {
// Find the join table based on the two model names pluralized,
// sorted alphabetically and with an underscore separating them
$through = array(inflector::plural($this->foreign['model']), inflector::plural($model));
// Sort
sort($through);
// Bring them back together
$this->through = implode('_', $through);
}
$this->through = array('model' => $this->through, 'columns' => array(inflector::singular($model) . ':foreign_key', inflector::singular($this->foreign['model']) . ':foreign_key'));
}
parent::initialize($model, $column);
}
示例3: habtm
public function habtm($model = NULL, $table = NULL, $id = NULL)
{
if (!$id and !$table) {
$table = $model;
$model = NULL;
}
if (!empty($this->form->model[$model])) {
$model = $this->form->model[$model];
} elseif ($id) {
$model = ORM::factory($model, $id);
$this->form->model[$model->object_name] = $model;
} elseif (!is_object($model)) {
// if no model is specified, use the last loaded model
foreach ($this->form->model as $key => $_model) {
$model = $this->form->model[$key];
$table = $table;
break;
}
}
$model_name = $model->object_name;
$keyname = "{$model_name}.{$table}";
$this->habtm_name[$keyname] = ORM::factory($table)->primary_val;
$this->habtm_plural[$keyname] = inflector::plural($table);
$this->habtm_table[$keyname] = $table;
$this->habtm_model[$keyname] = $model;
$values = array();
foreach (ORM::factory($this->habtm_table[$keyname])->find_all() as $option) {
$values[$option->id] = $option->{$this->habtm_name[$keyname]};
$this->elements[$keyname][] = $option->{$this->habtm_name[$keyname]};
}
$this->habtm_table[$keyname] = inflector::plural($this->habtm_table[$keyname]);
$this->form->add_group($this->habtm_table[$keyname] . '[]', $values)->set($this->habtm_table[$keyname], 'required', FALSE);
$this->fill_initial_values($keyname);
}
示例4: route_products_and_categories
/**
* Add routes for products
* @Developer brandon
* @Date Oct 19, 2010
*/
public static function route_products_and_categories()
{
foreach (ORM::factory('product')->find_all() as $object) {
Kohana::config_set('routes.' . $object->show_path(false), inflector::plural($object->object_name) . '/show/' . $object);
}
foreach (ORM::factory('category')->find_all() as $object) {
Kohana::config_set('routes.' . $object->show_path(false), inflector::plural($object->object_name) . '/show/' . $object);
}
}
示例5: __construct
public function __construct()
{
parent::__construct();
// load the database
$this->db = Database::instance();
// From the ORM example, this works out the table name from the model name
empty($this->class) and $this->class = strtolower(substr(get_class($this), 0, -6));
empty($this->table) and $this->table = inflector::plural($this->class);
// load the table stuff up
$this->_load();
}
示例6: delete_expired
/**
* Deletes all expired tokens.
*
* @return void
*/
public function delete_expired()
{
// Make sure the table is defined.....
if (!$this->_table) {
// Set the table name to the plural model name
$this->_table = inflector::plural(strtolower(substr(get_class($this), 6)));
}
// Delete all expired tokens
DB::delete($this->_table)->where('expires', '<', time())->execute($this->_db);
return $this;
}
示例7: __construct
public function __construct()
{
parent::__construct();
if (in_array(Router::$method, $this->excluded_actions)) {
Event::run('system.404');
}
if (!$this->model_name) {
$this->model_name = inflector::singular(Router::$controller);
}
$this->plural = inflector::plural($this->model_name);
$this->directory = $this->base_route . $this->plural;
// Do not render, by default, if the request is an ajax request
if (request::is_ajax()) {
$this->auto_render = false;
}
}
示例8: date
?>
">
<td><strong><?php
echo $item->reference_no;
?>
</strong></td>
<td><strong><?php
echo $item->code;
?>
</strong></td>
<td><strong><?php
echo $item->item_name;
?>
</td>
<td class="text-center"><?php
echo "{$item->quantity} " . inflector::plural($item->unit, $item->quantity);
?>
</td>
<td><?php
echo date('D M d, Y', strtotime($item->expiration_date));
?>
</td>
<td>
<div class="btn-group">
<a href="javascript:void(0);" data-item-id="<?php
echo $item->id;
?>
" class="btn bgm-bluegray btn-xs item-edit">Edit</a>
<a href="javascript:void(0);" data-item-id="<?php
echo $item->id;
?>
示例9: createJoinRecords
/**
* Generate any records that represent joins from this model to another.
*/
private function createJoinRecords()
{
if (array_key_exists('joinsTo', $this->submission)) {
foreach ($this->submission['joinsTo'] as $model => $ids) {
// $ids is now a list of the related ids that should be linked to this model via
// a join table.
$table = inflector::plural($model);
// Get the list of ids that are missing from the current state
$to_add = array_diff($ids, $this->{$table}->as_array());
// Get the list of ids that are currently joined but need to be disconnected
$to_delete = array_diff($this->{$table}->as_array(), $ids);
$joinModel = inflector::singular($this->join_table($table));
// Remove any joins that are to records that should no longer be joined.
foreach ($to_delete as $id) {
// @todo: This could be optimised by not using ORM to do the deletion.
$delModel = ORM::factory($joinModel, array($this->object_name . '_id' => $this->id, $model . '_id' => $id));
$delModel->delete();
}
// And add any new joins
foreach ($to_add as $id) {
$addModel = ORM::factory($joinModel);
$addModel->validate(new Validation(array($this->object_name . '_id' => $this->id, $model . '_id' => $id)), true);
}
}
$this->save();
}
return true;
}
示例10: addJoinForAttr
/**
* Adds the join required for a custom attribute to the query.
*/
private function addJoinForAttr(&$query, $type, $attr, $forceOuter)
{
$id = $attr->id;
// can only use an inner join for definitely required fields. If they are required
// only at the per-survey level, we must use left joins as the survey could vary per record.
$join = strpos($attr->validation_rules, 'required') === false || $forceOuter ? 'LEFT JOIN' : 'JOIN';
// find out what alias and field name the query uses for the table & field we need to join to
// (samples.id, occurrences.id or locations.id).
$rootIdAttr = inflector::plural($type) . '_id_field';
$rootId = $this->reportReader->{$rootIdAttr};
// construct a join to the attribute values table so we can get the value out.
$query = str_replace('#joins#', "{$join} " . $type . "_attribute_values {$type}{$id} ON {$type}{$id}." . $type . "_id={$rootId} AND {$type}{$id}." . $type . "_attribute_id={$id} AND {$type}{$id}.deleted=false\n #joins#", $query);
return $join;
}
示例11: count
<li>
<a href="<?php
echo $profile->local_url;
?>
"><img src="<?php
echo $profile->avatar_url;
?>
" alt="<?php
echo $profile;
?>
" /></a>
<a href="<?php
echo $profile->local_url;
?>
" class="member_name"><?php
echo $profile;
?>
</a>
<span class="descr"><?php
echo $profile->tagline;
?>
</span>
<a href="<?php
echo $profile->local_url;
?>
#Projects" class="involved_in"><?php
$project_count_for_profile = count($profile->projects);
echo $project_count_for_profile, ' ', inflector::plural('project', $project_count_for_profile);
?>
</a>
</li>
示例12: check_record_access
protected function check_record_access($entity, $id, $website_id, $sharing = false)
{
// if $id is null, then we have a new record, so no need to check if we have access to the record
if (is_null($id)) {
return true;
}
$table = inflector::plural($entity);
$viewname = 'list_' . $table;
if (!$this->db) {
$this->db = new Database();
}
$fields = postgreSQL::list_fields($viewname, $this->db);
if (empty($fields)) {
Kohana::log('info', $viewname . ' not present so cannot access entity');
throw new EntityAccessError('Access to entity ' . $entity . ' not available via requested view.', 1003);
}
$this->db->from("{$viewname} as record");
$this->db->where(array('record.id' => $id));
if (!in_array($entity, $this->allow_full_access)) {
if (array_key_exists('website_id', $fields)) {
// check if a request for shared data is being made. Also check this is valid to prevent injection.
if ($sharing && preg_match('/[reporting|peer_review|verification|data_flow|moderation]/', $sharing)) {
// request specifies the sharing mode (i.e. the task being performed, such as verification, moderation). So
// we can use this to work out access to other website data.
$this->db->join('index_websites_website_agreements as iwwa', array('iwwa.from_website_id' => 'record.website_id', 'iwwa.receive_for_' . $sharing . "='t'" => ''), NULL, 'LEFT');
$this->db->where('record.website_id IS NULL');
$this->db->orwhere('iwwa.to_website_id', $this->website_id);
} else {
$this->db->in('record.website_id', array(null, $this->website_id));
}
} elseif (!$this->in_warehouse) {
Kohana::log('info', $viewname . ' does not have a website_id - access denied');
throw new EntityAccessError('No access to entity ' . $entity . ' allowed.', 1004);
}
}
$number_rec = $this->db->count_records();
return $number_rec > 0 ? true : false;
}
示例13: __construct
/**
* Initialize the fields and add validation rules based on field properties.
*
* @return void
*/
protected function __construct()
{
if ($this->_init) {
if ($this->state() === 'loading') {
// Object loading via mysql_fetch_object or similar has finished
$this->state('loaded');
}
// Can only be called once
return;
}
// Initialization has been started
$this->_init = TRUE;
// Set up the fields
$this->_init();
if (!$this->_model) {
// Set the model name based on the class name
$this->_model = strtolower(substr(get_class($this), 6));
}
if (!$this->_table) {
// Set the table name to the plural model name
$this->_table = inflector::plural($this->_model);
}
foreach ($this->_fields as $name => $field) {
if ($field->primary === TRUE) {
if (!$this->_primary_key) {
// This is the primary key
$this->_primary_key = $name;
} else {
if (is_string($this->_primary_key)) {
// More than one primary key found, create a list of keys
$this->_primary_key = array($this->_primary_key);
}
// Add this key to the list
$this->_primary_key[] = $name;
}
}
}
foreach ($this->_fields as $name => $field) {
if ($field instanceof Sprig_Field_ForeignKey and !$field->model) {
if ($field instanceof Sprig_Field_HasMany) {
$field->model = Inflector::singular($name);
} else {
$field->model = $name;
}
}
if ($field instanceof Sprig_Field_ManyToMany) {
if (!$field->through) {
// Get the model names for the relation pair
$pair = array(strtolower($this->_model), strtolower($field->model));
// Sort the model names alphabetically
sort($pair);
// Join the model names to get the relation name
$pair = implode('_', $pair);
if (!isset(Sprig::$_relations[$pair])) {
// Must set the pair key before loading the related model
// or we will fall into an infinite recursion loop
Sprig::$_relations[$pair] = TRUE;
$tables = array($this->table(), Sprig::factory($field->model)->table());
// Sort the table names alphabetically
sort($tables);
// Join the table names to get the table name
Sprig::$_relations[$pair] = implode('_', $tables);
}
// Assign by reference so that changes to the pivot table
// will carry over to all models
$field->through =& Sprig::$_relations[$pair];
}
}
if (!$field->column) {
// Create the key based on the field name
if ($field instanceof Sprig_Field_BelongsTo) {
if (isset($field->foreign_key) and $field->foreign_key) {
$fk = $field->foreign_key;
} else {
$fk = Sprig::factory($field->model)->fk();
}
$field->column = $fk;
} elseif ($field instanceof Sprig_Field_HasOne) {
$field->column = $this->fk();
} elseif ($field instanceof Sprig_Field_ForeignKey) {
// This field is probably a Many and does not need a column
} else {
$field->column = $name;
}
}
if (!$field->label) {
$field->label = Inflector::humanize($name);
}
if ($field->null) {
// Fields that allow NULL values must accept empty values
$field->empty = TRUE;
}
if ($field->editable) {
if (!$field->empty and !isset($field->rules['not_empty'])) {
// This field must not be empty
//.........这里部分代码省略.........
示例14: init
/**
* Initialize the fields and add validation rules based on field properties.
*
* @return void
*/
public function init()
{
if ($this->_init) {
// Can only be called once
return;
}
$this->_init = TRUE;
// Set up the fields
$this->_init();
if (!$this->_model) {
// Set the model name based on the class name
$this->_model = strtolower(substr(get_class($this), 6));
}
if (!$this->_table) {
// Set the table name to the plural model name
$this->_table = inflector::plural($this->_model);
}
foreach ($this->_fields as $name => $field) {
if ($field->primary === TRUE) {
if (!$this->_primary_key) {
// This is the primary key
$this->_primary_key = $name;
} else {
if (is_string($this->_primary_key)) {
// More than one primary key found, create a list of keys
$this->_primary_key = array($this->_primary_key);
}
// Add this key to the list
$this->_primary_key[] = $name;
}
}
}
foreach ($this->_fields as $name => $field) {
if ($field->column === NULL) {
// Create the key based on the field name
if ($field instanceof Sprig_Field_ForeignKey) {
$field->column = $name . '_id';
} else {
$field->column = $name;
}
}
if ($field instanceof Sprig_Field_ManyToMany) {
$this->_many[$name] = $name;
$model = Sprig::factory($field->model);
if (!$field->through) {
// Use the both tables as the pivot
$tables = array($this->_table, $model->table());
// Sort the tables by name
sort($tables);
// Concat the tables using an underscore
$field->through = implode('_', $tables);
}
}
if ($field->label === NULL) {
$field->label = Inflector::humanize($name);
}
if ($field->editable) {
if (!$field->empty and !isset($field->rules['not_empty'])) {
// This field must not be empty
$field->rules['not_empty'] = NULL;
}
if ($field->choices and !isset($field->rules['in_array'])) {
// Field must be one of the available choices
$field->rules['in_array'] = array(array_keys($field->choices));
}
if (!empty($field->min_length)) {
$field->rules['min_length'] = array($field->min_length);
}
if (!empty($field->max_length)) {
$field->rules['max_length'] = array($field->max_length);
}
}
}
}
示例15: gpx_encode
/**
* Encodes an array as gpx - fixed format XML style.
* Uses $this->entity to decide the name of the root element.
*/
protected function gpx_encode($array, $indent = false)
{
// if we are outputting a specific record, root is singular
if ($this->uri->total_arguments()) {
$root = $this->entity;
// We don't need to repeat the element for each record, as there is only 1.
$array = $array[0];
} else {
$root = inflector::plural($this->entity);
}
$data = '<?xml version="1.0"?>' . ($indent ? "\r\n" : '') . '<gpx creator="Indicia" version="1.1">' . ($indent ? "\r\n\t" : '') . '<metadata>' . ($indent ? "\r\n\t\t" : '') . '<name>' . $root . '</name>' . ($indent ? "\r\n\t\t" : '') . '<author>Indicia</author>' . ($indent ? "\r\n\t\t" : '') . '<desc>Created by Indicia</desc>' . ($indent ? "\r\n\t\t" : '') . '<time>' . date(DATE_ATOM) . '</time>' . ($indent ? "\r\n\t" : '') . '</metadata>' . ($indent ? "\r\n" : '');
$recordNum = 1;
foreach ($array["records"] as $element => $value) {
$data .= $this->gpx_encode_array($recordNum, $root, $value, $indent, 1);
$recordNum++;
}
$data .= "</gpx>";
return $data;
}