本文整理汇总了PHP中entity_selector::add_table方法的典型用法代码示例。如果您正苦于以下问题:PHP entity_selector::add_table方法的具体用法?PHP entity_selector::add_table怎么用?PHP entity_selector::add_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entity_selector
的用法示例。
在下文中一共展示了entity_selector::add_table方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function alter_values()
{
$parent = new entity_selector();
$parent->add_field('entity2', 'id', 'parent_id');
$parent->add_table('allowable_relationship2', 'allowable_relationship');
$parent->add_table('relationship2', 'relationship');
$parent->add_table('entity2', 'entity');
$parent->add_relation('entity2.id = relationship2.entity_b');
$parent->add_relation('entity.id = relationship2.entity_a');
$parent->add_relation('relationship2.type = allowable_relationship2.id');
$parent->add_relation('allowable_relationship2.name LIKE "%parent%"');
$parent->set_order('sortable.sort_order');
$this->es->swallow($parent);
$this->remove_column('id');
}
示例2: die
$user_id = get_user_id($current_user);
if (empty($user_id)) {
die('<h1>Sorry.</h1><p>You do not have permission to move entities among sites.</p><p>Only Reason admins may do that.</p></body></html>');
} elseif (!reason_user_has_privs($user_id, 'db_maintenance')) {
die('<h1>Sorry.</h1><p>You do not have permission to move entities among sites.</p><p>Only Reason admins who have database maintenance privs may do that.</p></body></html>');
}
echo '<h1>Move Entities Among Sites</h1>';
echo '<h2>Step 1 of 2: Choose site and entity type</h2>';
$es = new entity_selector();
$es->add_type(id_of('site'));
$es->add_left_relationship($user_id, relationship_id_of('site_to_user'));
$es->set_order('entity.name ASC');
$sites = $es->run_one();
$es = new entity_selector();
$es->add_type(id_of('type'));
$es->add_table('ar', 'allowable_relationship');
$es->add_relation('ar.relationship_a = ' . id_of('site'));
$types = $es->run_one();
$site_options = array();
foreach ($sites as $site) {
$site_options[$site->id()] = $site->get_value('name');
}
$type_options = array();
foreach ($types as $type) {
$type_options[$type->id()] = $type->get_value('name');
}
$d = new DiscoMoveEntities();
$d->add_element('site_id', 'select', array('options' => $site_options));
$d->add_element('type_id', 'select', array('options' => $type_options));
$d->add_element('options_comment', 'comment', array('text' => '<h4>Optional entity filters:</h4>'));
$d->add_element('creation_date_start', 'textDateTime_js');
示例3:
function get_sharable_relationships()
{
$es = new entity_selector();
$es->add_type(id_of('type'));
$es->add_table('access', 'allowable_relationship');
$es->add_table('access_rel', 'relationship');
$es->add_table('shares', 'allowable_relationship');
$es->add_table('shares_rel', 'relationship');
//linking relations
$es->add_relation('entity.id = access_rel.entity_b');
$es->add_relation('entity.id = shares_rel.entity_b');
$es->add_relation('access_rel.type = access.id');
$es->add_relation('shares_rel.type = shares.id');
//access relations
$es->add_relation('access.name = "site_to_type"');
$es->add_relation('access_rel.entity_a = ' . $this->site_id);
$es->add_relation('access_rel.entity_b = entity.id');
//sharing relations
$es->add_relation('shares.name = "site_shares_type"');
$es->add_relation('shares_rel.entity_a != ' . $this->site_id);
$es->add_relation('shares_rel.entity_b = entity.id');
if ($this->site_is_live()) {
$es->add_table('site_table', 'site');
$es->add_relation('shares_rel.entity_a = site_table.id');
$es->add_relation('site_table.site_state = "Live"');
}
return $es->run_one();
}
示例4: elseif
/**
* Adds a new field to the entity which is actually not a field of entity, but rather a field of
* an entity which is related to the current entities. The entities selected by the ES will be
* on the right side of the relationship.
* Will return multiples of an entity if it has multiples of the same relationship. Not sure
* how to change this.
* @param string $rel_name the name of the relationship between the entities
* @param string $table the table where the field is
* @param string $field the name of the field to be selected
* @param string $alias that alias for the field
* @param mixed $limit_results true return only row for which the related value is defined
* false to return all results even if the value does not exist
* string or array to limit results to the values passed
* @return void
*/
function add_right_relationship_field($rel_name, $table, $field, $alias, $limit_results = true)
{
if ($rel_name != "owns" && $rel_name != "borrows" && !empty($rel_name)) {
$rel_type_id = relationship_id_of($rel_name);
} elseif ($rel_name == 'owns' || $rel_name == 'borrows') {
if (empty($this->type)) {
$call_info = array_shift(debug_backtrace());
$code_line = $call_info['line'];
$file = array_pop(explode('/', $call_info['file']));
$msg = 'entity selector method add_right_relationship_field called by ' . $file . ' on line ' . $code_line . ' on a generic "owns" or "borrows" relationship when the type has not been set on the entity selector.';
trigger_error($msg, WARNING);
return false;
} elseif ($rel_name == "owns") {
$rel_type_id = get_owns_relationship_id(reset($this->type));
} elseif ($rel_name == "borrows") {
$rel_type_id = get_borrows_relationship_id(reset($this->type));
}
}
if (empty($rel_type_id)) {
trigger_error('add_right_relationship_field failed - an id could not be determined from the relationship name provided');
return false;
}
if ($limit_results === false) {
$cur_es = carl_clone($this);
$this->union = true;
}
$es = new entity_selector();
$es->add_table('relationship', 'relationship');
$es->add_table('__entity__', 'entity');
if ($table != 'entity') {
$es->add_table($table);
}
$tables = $this->merge_tables($es);
if (!empty($tables['relationship'])) {
$r = $tables['relationship'];
} else {
$r = 'relationship';
}
if (!empty($tables['__entity__'])) {
$e = $tables['__entity__'];
} else {
$e = '__entity__';
}
if ($table == 'entity') {
$t = $e;
} else {
if (!empty($tables[$table])) {
$t = $tables[$table];
} else {
$t = $table;
}
}
if ($e != $t) {
$this->add_relation($e . '.id = ' . $t . '.id');
}
$this->add_relation($e . '.id = ' . $r . '.entity_a');
$this->add_relation('entity.id = ' . $r . '.entity_b');
$this->add_relation($r . '.type = ' . $rel_type_id);
$this->add_field($t, $field, $alias);
if ($this->_env['restrict_site'] and !empty($this->_env['site'])) {
$this->add_relation('(' . $r . '.site=0 OR ' . $r . '.site=' . addslashes($this->_env['site']) . ')');
}
if ($limit_results === false) {
$this->union_fields[end($this->fields)] = '0 as ' . $alias;
$this->diff['fields'][] = array_diff_assoc($this->fields, $cur_es->fields);
$this->diff['tables'][] = array_diff_assoc($this->tables, $cur_es->tables);
$this->diff['relations'][] = array_diff_assoc($this->relations, $cur_es->relations);
} elseif (is_string($limit_results) || is_array($limit_results)) {
if (is_array($limit_results) && empty($limit_results)) {
$this->add_relation('0 = 1');
} else {
$limit_values = is_string($limit_results) ? array($limit_results) : $limit_results;
array_walk($limit_values, 'db_prep_walk');
$this->add_relation($t . '.' . $field . ' IN (' . implode(',', $limit_values) . ')');
}
}
return array($alias => array('table_orig' => $table, 'table' => $t, 'field' => $field));
}