本文整理汇总了PHP中entity_selector::add_left_relationship方法的典型用法代码示例。如果您正苦于以下问题:PHP entity_selector::add_left_relationship方法的具体用法?PHP entity_selector::add_left_relationship怎么用?PHP entity_selector::add_left_relationship使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类entity_selector
的用法示例。
在下文中一共展示了entity_selector::add_left_relationship方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
function init($args = array())
{
parent::init($args);
$site = new entity($this->site_id);
if (!empty($this->params['sites'])) {
$this->child_sites = array();
foreach ($this->params['sites'] as $unique_name) {
if ($id = id_of($unique_name)) {
$e = new entity($id);
if ($e->get_value('type') == id_of('site') && ($site->get_value('site_state') != 'Live' || $e->get_value('site_state') == 'Live')) {
$this->child_sites[$id] = $e;
}
}
}
} else {
$es = new entity_selector();
$es->description = 'Getting child sites of this site';
$es->add_type(id_of('site'));
$es->add_left_relationship($this->site_id, relationship_id_of('parent_site'));
$es->set_order('entity.name');
if ($site->get_value('site_state') == 'Live') {
$es->add_relation('site_state="Live"');
}
$this->child_sites = $es->run_one();
}
}
示例2: entity
function load_by_type($type_id, $id, $user_id)
{
$this->_id = $id;
$this->_original = new entity($this->_id);
// load all fields used by this type
$q = 'DESC entity';
$r = db_query($q, 'Unable to get entity description');
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
list($type, $args) = $this->plasmature_type_from_db_type($row['Field'], $row['Type']);
$this->add_element($row['Field'], $type, $args);
}
// get tables associated with this type
$es = new entity_selector();
$es->description = 'disco reason: load_by_type: tables to type';
$es->add_type(id_of('content_table'));
$es->add_right_relationship($type_id, relationship_id_of('type_to_table'));
$tables = $es->run_one();
unset($es);
// make an element for each field the type has
foreach ($tables as $tid => $table) {
// grab the type's entity tables and fields
$es = new entity_selector();
$es->description = 'disco reason 2: load_by_type: fields associated with table ' . $table->get_value('name');
$es->add_type(id_of('field'));
$es->add_left_relationship($tid, relationship_id_of('field_to_entity_table'));
$fields = $es->run_one('', 'Live', 'field es');
unset($es);
foreach ($fields as $fid => $field) {
$args = array();
$type = '';
// set the plasmature type if specified by the field, otherwise look up the default for the database type
list($type, $args) = $this->plasmature_type_from_db_type($field->get_value('name'), $field->get_value('db_type'));
if ($field->get_value('plasmature_type')) {
$type = $field->get_value('plasmature_type');
}
// hook for plasmature arguments here
$this->add_element($field->get_value('name'), $type, $args, $field->get_value('db_type'));
}
}
// load values
$elements = $this->_original->get_values();
foreach ($elements as $key => $val) {
if (isset($val)) {
$this->set_value($key, $val);
}
}
$this->init();
$this->change_element_type('type', 'hidden');
$this->set_value('type', $type_id);
$this->change_element_type('last_edited_by', 'hidden');
$this->set_value('last_edited_by', $user_id);
if (!reason_user_has_privs($user_id, 'edit_unique_names')) {
$this->change_element_type('unique_name', 'hidden');
} elseif ($this->get_value('unique_name')) {
$this->change_element_type('unique_name', 'solidText');
}
}
示例3: array
function do_updates($mode, $reason_user_id)
{
if ($mode != 'run' && $mode != 'test') {
trigger_error('$mode most be either "run" or "test"');
return;
}
$messages = array();
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('view_type'));
$es->add_relation('url = "sections_and_issues.php"');
$es->set_num(1);
$view_types = $es->run_one();
if (empty($view_types)) {
if ('test' == $mode) {
echo '<p>Would have added the view type sections_and_issues.php and the Sections and Issues view</p>' . "\n";
return;
} else {
$view_type_id = reason_create_entity(id_of('master_admin'), id_of('view_type'), $reason_user_id, 'News Sections and Issues', array('url' => 'sections_and_issues.php'));
$view_type = new entity($view_type_id);
echo '<p>Added the view type sections_and_issues.php</p>' . "\n";
}
} else {
echo '<p>sections_and_issues.php view type already added</p>' . "\n";
$view_type = current($view_types);
}
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('view'));
$es->add_left_relationship($view_type->id(), relationship_id_of('view_to_view_type'));
$es->set_num(1);
$views = $es->run_one();
if (empty($views)) {
if ('test' == $mode) {
echo '<p>Would have added the Sections and Issues view</p>' . "\n";
} else {
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('field'));
$es->add_relation('entity.name = "status"');
$es->set_num(1);
$fields = $es->run_one();
$view_id = reason_create_entity(id_of('master_admin'), id_of('view'), $reason_user_id, 'News Sections and Issues', array('display_name' => 'Sections and Issues'));
create_relationship($view_id, $view_type->id(), relationship_id_of('view_to_view_type'));
create_relationship($view_id, id_of('news'), relationship_id_of('view_to_type'));
if (!empty($fields)) {
$field = current($fields);
create_relationship($view_id, $field->id(), relationship_id_of('view_columns'));
create_relationship($view_id, $field->id(), relationship_id_of('view_searchable_fields'));
}
echo '<p>Added sections and issue view</p>';
}
} else {
echo '<p>sections and issues view already added.</p>' . "\n";
}
}
示例4: foreach
function setup_associated_items()
{
// populate associated entity selector from scratch
$ass_es = new entity_selector();
$ass_es->add_type($this->type_id);
if ($this->rel_direction == 'a_to_b') {
$ass_es->add_right_relationship($this->admin_page->id, $this->admin_page->rel_id);
} else {
$ass_es->add_left_relationship($this->admin_page->id, $this->admin_page->rel_id);
}
$ass_es->add_right_relationship_field('owns', 'entity', 'id', 'site_owner_id');
if ($this->rel_direction == 'a_to_b' && $this->check_is_rel_sortable()) {
$this->columns['rel_sort_order'] = true;
$ass_es->add_field('relationship', 'id', 'rel_id');
$ass_es->add_rel_sort_field($this->admin_page->id);
$ass_es->set_order('relationship.rel_sort_order ASC');
if ($this->_cur_user_has_edit_privs() && !$this->get_relationship_lock_state()) {
$this->alter_order_enable = true;
}
} else {
$ass_es->add_field('relationship', 'site', 'rel_site_id');
}
if ($this->assoc_viewer_order_by($ass_es)) {
$this->alter_order_enable = false;
}
$this->ass_vals = $ass_es->run_one();
// check sharing on associated entities
foreach ($this->ass_vals as $k => $val) {
// setup sharing value
if ($this->site_id == $val->get_value('site_owner_id')) {
$this->ass_vals[$k]->set_value('sharing', 'owns');
} else {
$this->ass_vals[$k]->set_value('sharing', $this->check_borrow_status($k));
}
}
// this verifies and updates the associated items rel_sort_order if this is an a to b relationship
if ($this->rel_direction == 'a_to_b' && $this->check_is_rel_sortable()) {
if (count($this->ass_vals) == 1 && isset($this->columns['rel_sort_order'])) {
unset($this->columns['rel_sort_order']);
}
if ($ass_es->orderby == 'relationship.rel_sort_order ASC') {
$rel_update_array = $this->validate_rel_sort_order($this->ass_vals, true);
} else {
$rel_update_array = $this->validate_rel_sort_order($this->ass_vals);
}
if (count($rel_update_array) > 0) {
foreach ($rel_update_array as $k => $v) {
update_relationship($k, array('rel_sort_order' => $v));
}
}
}
}
示例5:
function get_children($child)
{
$es = new entity_selector();
$es->description = 'Selecting children of the page id ' . $child->id();
// find all the children of this page
$es->add_type(id_of('minisite_page'));
$es->add_left_relationship($child->id(), relationship_id_of('minisite_page_parent'));
if ($this->params['show_only_pages_in_nav']) {
$this->es->add_relation('nav_display = "Yes"');
}
$es->set_order('sortable.sort_order ASC');
return $es->run_one();
}
示例6: entity
/**
* Quick and dirty helper function that gets the sites with available associations with that type.
*
* This function just checks for all sites that are currently set to share objects of the given type.
* If the current site is live, it only selects those other sites which are also live. It does
* not check the sites to see if the site is actually sharing anything.
* @return array An array of entities of the available sites in alphabetical order
*/
function get_sites_with_available_associations()
{
$cur_site = new entity($this->page->site_id);
$es = new entity_selector();
$es->add_type(id_of('site'));
if ($cur_site->get_value('site_state') == 'Live') {
$es->add_relation('site.site_state = "Live"');
}
$es->add_relation('entity.id != ' . $this->page->site_id);
$es->add_left_relationship($this->page->type_id, relationship_id_of('site_shares_type'));
$es->set_order('name ASC');
$results = $es->run_one();
$return_array = array();
foreach ($results as $e) {
$return_array[$e->id()] = $e->get_value('name');
}
return $return_array;
}
示例7: init
function init($args = array())
{
$es = new entity_selector($this->site_id);
$es->description = 'Selecting publications for this page';
$es->add_type(id_of('publication_type'));
$es->add_right_relationship($this->page_id, relationship_id_of('page_to_publication'));
$es->set_num(1);
$publications = $es->run_one();
if (!empty($publications)) {
$this->publication = current($publications);
if ($this->publication->get_value('has_sections') == 'yes') {
$es = new entity_selector($this->site_id);
$es->description = 'Selecting news sections for this publication';
$es->add_type(id_of('news_section_type'));
$es->add_left_relationship($this->publication->id(), relationship_id_of('news_section_to_publication'));
$es->set_order('sortable.sort_order ASC');
$this->sections = $es->run_one();
}
}
if (!empty($this->sections) && !empty($this->publication) && $this->publication->get_value('has_issues')) {
if (!empty($this->request['issue_id'])) {
$iss = new entity($this->request['issue_id']);
if ($iss->get_values() && $iss->get_value('type') == id_of('issue_type')) {
$this->issue = $iss;
}
} else {
$es = new entity_selector($this->site_id);
$es->description = 'Selecting issues for this publication';
$es->add_type(id_of('issue_type'));
$es->limit_tables(array('dated', 'show_hide'));
$es->limit_fields('dated.datetime');
$es->set_order('dated.datetime DESC');
$es->add_relation('show_hide.show_hide = "show"');
$es->add_left_relationship($this->publication->id(), relationship_id_of('issue_to_publication'));
$es->set_num(1);
$issues = $es->run_one();
if (!empty($issues)) {
$this->issue = current($issues);
}
}
}
}
示例8: array
function grab_sites($name, $site_type_id_array)
{
$sites_by_type = array();
$sites_by_type[$this->id_of_site_type] = array();
$sites_by_type[$this->id_of_non_reason_site_type] = array();
foreach ($site_type_id_array as $site_type_id) {
$r_es = new entity_selector();
$r_es->description = 'Getting all ' . $name;
$r_es->add_type($this->id_of_site_type);
$r_es->add_relation('site.site_state = "Live"');
$r_es->add_left_relationship($site_type_id, relationship_id_of('site_to_site_type'));
$r_es->set_order('entity.name ASC');
$sites_by_type[$this->id_of_site_type] += $r_es->run_one();
$nr_es = new entity_selector();
$nr_es->description = 'Getting all ' . $name;
$nr_es->add_type($this->id_of_non_reason_site_type);
$nr_es->add_left_relationship($site_type_id, relationship_id_of('non_reason_site_to_site_type'));
$nr_es->add_relation('site.site_state = "Live"');
$sites_by_type[$this->id_of_non_reason_site_type] += $nr_es->run_one();
}
$this->list_sites($sites_by_type, $name);
}
示例9: _get_path_from_entities
private static function _get_path_from_entities($media_file, $tmp_file_name, $media_work, $extra_dir)
{
if (!$media_work) {
$es = new entity_selector();
$es->add_type(id_of('av'));
$es->add_left_relationship($media_file->get_value('id'), relationship_id_of('av_to_av_file'));
$media_work = current(array_merge($es->run_one(), $es->run_one('', 'Pending', 'Deleted')));
}
if ($media_work) {
if ($tmp_file_name) {
$extension = end(explode('.', $tmp_file_name));
} else {
$extension = end(explode('.', $media_work->get_value('original_filename')));
}
if ($extension) {
return self::_generate_dir_path($media_work, $extra_dir) . self::_generate_name($media_work->get_value('original_filename'), $extension, $extra_dir, $media_file, $media_work);
} else {
trigger_error('Invalid filename: ' . $tmp_file_name . '. It has no extension.');
}
} else {
trigger_error('No Media Work is associated with Media File with id ' . $media_file->get_value('id'));
}
}
示例10: init
/**
* Standard Module init function
*
* @return void
*/
function init()
{
parent::init();
if (!empty($this->admin_page->id)) {
$this->issue = new entity($this->admin_page->id);
}
if (empty($this->issue) || $this->issue->get_value('type') != id_of('issue_type')) {
trigger_error('Sort Posts module run on a non-issue entity', EMERGENCY);
die;
}
$this->admin_page->title = 'Sort Posts on issue "' . $this->issue->get_value('name') . '"';
$es = new entity_selector($this->admin_page->site_id);
$es->add_type(id_of('news'));
$es->set_sharing('owns');
$es->add_left_relationship($this->issue->id(), relationship_id_of('news_to_issue'));
$es->set_order('dated.datetime DESC');
$this->posts = $es->run_one();
$user = new entity($this->admin_page->user_id);
foreach ($this->posts as $id => $post) {
if (!$post->user_can_edit_field('datetime', $user)) {
$this->locked_posts[$id] = $post;
}
}
}
示例11: reason_user_sites
/**
* Get the sites a given user has administrative access to
*
* @param mixed $user entity or user id
* @return array of site entities
*/
function reason_user_sites($user)
{
if (is_object($user)) {
$user_id = $user->id();
} else {
$user_id = (int) $user;
}
if (empty($user_id)) {
trigger_error('reason_user_sites() requires a user entity or integer ID as its first parameter. Returning empty array.');
return array();
}
static $cache = array();
if (!isset($cache[$user_id])) {
$es = new entity_selector();
$es->add_type(id_of('site'));
$es->add_left_relationship($user_id, relationship_id_of('site_to_user'));
$es->limit_tables();
$es->limit_fields();
$cache[$user_id] = $es->run_one();
}
return $cache[$user_id];
}
示例12: current
function get_field_id($table_name, $field_name)
{
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('content_table'));
$es->add_relation('entity.name = "' . reason_sql_string_escape($table_name) . '"');
$es->set_num(1);
$tables = $es->run_one();
if (empty($tables)) {
trigger_error('Unable to find table named ' . $table_name);
return false;
}
$table = current($tables);
$es = new entity_selector(id_of('master_admin'));
$es->add_type(id_of('field'));
$es->add_left_relationship($table->id(), relationship_id_of('field_to_entity_table'));
$es->add_relation('entity.name = "' . reason_sql_string_escape($field_name) . '"');
$es->set_num(1);
$fields = $es->run_one();
if (empty($fields)) {
trigger_error('Unable to find table named ' . $field_name, ' in table named ' . $table_name);
return false;
}
$field = current($fields);
return $field->id();
}
示例13: die
echo '<script type="text/javascript" src="' . REASON_HTTP_BASE_PATH . 'js/move_entities.js"></script>' . "\n";
echo '</head><body>';
reason_include_once('function_libraries/user_functions.php');
force_secure_if_available();
$current_user = check_authentication();
$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');
}
示例14: current
} else {
echo '<p>Testing updates...</p>' . "\n";
}
$es = new entity_selector();
$es->add_type(id_of('content_table'));
$es->add_relation('entity.name = "site"');
$es->set_num(1);
$tables = $es->run_one();
if (empty($tables)) {
echo '<p>Unable to find site table. Major problem.</p>';
} else {
$table = current($tables);
$es = new entity_selector();
$es->add_type(id_of('field'));
$es->add_relation('entity.name IN ("use_custom_footer","custom_footer")');
$es->add_left_relationship($table->id(), relationship_id_of('field_to_entity_table'));
$es->set_num(2);
$fields = $es->run_one();
$fields_to_create = array('use_custom_footer' => 'enum(\'yes\',\'no\')', 'custom_footer' => 'text');
foreach ($fields as $field) {
unset($fields_to_create[$field->get_value('name')]);
}
if (empty($fields_to_create)) {
echo '<p>Fields exist; script has already been run.</p>';
} else {
if ($_POST['go'] != 'run') {
echo '<p>Would have created these fields:</p>';
pray($fields_to_create);
} else {
$update_fields = array();
foreach ($fields_to_create as $key => $value) {
示例15: array
function update_es()
{
// lets find the sites that share the type (except the current site) and limit our query to those sites
$prep_es = new entity_selector();
$prep_es->add_type(id_of('site'));
$prep_es->add_left_relationship($this->admin_page->type_id, relationship_id_of('site_shares_type'));
if ($this->site_is_live()) {
$prep_es->limit_tables('site');
$prep_es->limit_fields('site.site_state');
$prep_es->add_relation('site.site_state = "Live"');
$prep_es->add_relation('entity.id != "' . $this->admin_page->site_id . '"');
} else {
$prep_es->limit_tables();
$prep_es->limit_fields();
}
$this->sites_that_borrow_type = $prep_es->run_one();
$es = new entity_selector();
$es->add_type($this->admin_page->type_id);
$limiter = !empty($this->admin_page->request['search_site']) ? $this->admin_page->request['search_site'] : array_keys($this->sites_that_borrow_type);
if (empty($limiter)) {
$limiter = array("-1");
}
// no sites share type lets limit to site_id = -1, which will be no sites - this avoids a crash.
$es->add_right_relationship_field('owns', 'entity', 'id', 'site_id', $limiter);
$es->add_right_relationship_field('owns', 'entity', 'name', 'site');
$this->apply_order_and_limits($es);
$es->add_relation('(entity.no_share IS NULL OR entity.no_share = 0)');
// entity is shared
$this->es = $es;
}