function _get_events() { if(!isset($this->events)) { $es = new entity_selector($this->site_id); $es->add_type(id_of('event_type')); if(!in_array('archived',$this->params['show'])) { $es->add_relation('`last_occurence` >= "'.addslashes(date('Y-m-d')).'"'); } if(!in_array('upcoming',$this->params['show'])) { $es->add_relation('`datetime` < "'.addslashes(date('Y-m-d',time() + (60*60*24))).'"'); } if(!in_array('current',$this->params['show'])) { $es->add_relation('(`last_occurence` < "'.addslashes(date('Y-m-d')).'" OR `datetime` >= "'.addslashes(date('Y-m-d',time() + (60*60*24))).'")'); } $es->add_relation('`show_hide` = "show"'); $es->set_order($this->params['order']); $this->_modify_events_es($es); $events = $es->run_one(); $class = $this->get_model_class($this->params['model']); foreach($events as $id => $event) { $this->events[$id] = new $class($event); } if(empty($this->events)) $this->events = array(); } return $this->events; }
function run_error_checks() { parent::run_error_checks(); $es = new entity_selector(); $es->add_relation('audience_integration.directory_service_value = "' . reason_sql_string_escape($this->get_value('directory_service_value')) . '"'); $es->add_relation('entity.id != ' . $this->get_value('id')); $es->set_num(1); $conflicts = $es->run_one(id_of('audience_type')); if (!empty($conflicts)) { $this->set_error('directory_service_value', 'The Directory Service Value you entered ("' . $this->get_value('directory_service_value') . '") is already in use. Each audience must have a unique directory service value.'); } }
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'); }
function image_may_be_shown($id) { if ($this->params['alternate_source_page_id']) { $page_id = $this->params['alternate_source_page_id']; if (!($site_id = get_owner_site_id($page_id))) { $site_id = $this->site_id; } } else { $page_id = $this->cur_page->id(); $site_id = $this->site_id; } $es = new entity_selector(); $es->add_type(id_of('image')); $es->set_env('site', $site_id); $es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image')); $es->add_relation('entity.id = ' . addslashes($id)); $result = $es->run_one(); //echo 'given id='.$id; if (!empty($result)) { //echo 'returning true'; return true; } else { //echo 'returning false'; return false; } }
function _produce_borrowing_nav() { $ret = ''; $nes = new entity_selector(); $nes->add_type(id_of('type')); $nes->add_right_relationship($this->admin_page->site_id, relationship_id_of('site_cannot_edit_type')); $nes->add_relation('`entity`.`id` = "' . addslashes($this->admin_page->type_id) . '"'); $nes->set_num(1); $nes->limit_tables(); $nes->limit_fields(); $ns = $nes->run_one(); $show_edit = reason_user_has_privs($this->admin_page->user_id, 'edit') && !$this->admin_page->is_second_level() && empty($ns) ? true : false; /* $type = new entity($this->admin_page->type_id); $name = $type->get_value('plural_name') ? $type->get_value('plural_name') : $type->get_value('name'); if(function_exists('mb_strtolower')) $name = mb_strtolower($name); else $name = strtolower($name); */ $ret .= '<div class="borrowNav">' . "\n"; $ret .= '<ul>'; if ($show_edit) { $ret .= '<li><a href="' . $this->admin_page->get_owned_list_link($this->admin_page->type_id) . '"><img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/bullet_edit.png" alt="" /> Add & edit</a></li>'; } $ret .= '<li class="current"><strong><img src="' . REASON_HTTP_BASE_PATH . 'silk_icons/car.png" alt="" /> Borrow</strong></li>'; $ret .= '</ul>' . "\n"; $ret .= '</div>' . "\n"; // if(reason_user_has_privs($this->admin_page->user_id,'edit')) return $ret; }
function get_pages_needing_change() { if (!isset($this->pages_needing_change)) { $es = new entity_selector(); $es->add_type(id_of('minisite_page')); $es->enable_multivalue_results(); $es->limit_tables('page_node'); $es->limit_fields('custom_page'); $es->add_relation('page_node.custom_page = "blurb"'); $es->add_left_relationship_field('minisite_page_to_text_blurb', 'entity', 'id', 'blurb_id'); $result = $es->run_one(); foreach ($result as $k => $page) { $blurbs = is_array($page->get_value('blurb_id')) ? $page->get_value('blurb_id') : array($page->get_value('blurb_id')); foreach ($blurbs as $blurb_id) { $blurb = new entity($blurb_id); $content = $blurb->get_value('content'); $demoted_content = demote_headings($content, 1); if ($content == $demoted_content) { $pages_needing_page_type_change[$k] = $k; } } } $this->pages_needing_change = isset($pages_needing_page_type_change) ? array_keys($pages_needing_page_type_change) : false; } return $this->pages_needing_change; }
function get_pages($page_types) { $es = new entity_selector(); $es->add_type(id_of('minisite_page')); $es->add_relation('custom_page IN ("' . implode('","', $page_types) . '")'); return $es->run_one(); }
function name_es($name) { $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "' . $name . '"'); $results = $es->run_one(); return $results; }
/** * @return object loki 1 entity if it exists */ protected function get_loki_1_entity() { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('html_editor_type')); $es->add_relation('entity.name = "Loki 1"'); $es->set_num(1); $result = $es->run_one(); return !empty($result) ? reset($result) : FALSE; }
function init_list() { if ($this->site_specific) { $es = new entity_selector($this->parent->site_id); $es->description = "Getting the jobs on this site"; } else { $es = new entity_selector(); $es->description = "Getting all jobs -- not just on this site"; } $es->add_type(id_of('job')); $es->add_relation('show_hide.show_hide = "show"'); $es->add_relation('job.posting_start <= "' . date('Y-m-d') . '"'); $es->add_relation('adddate( job.posting_start, interval duration.duration day ) >= "' . date('Y-m-d') . '"'); $this->jobs = $es->run_one(); if (!empty($this->request['job_id']) && !empty($this->jobs[$this->request['job_id']])) { $this->_add_crumb($this->jobs[$this->request['job_id']]->get_value('name')); } }
protected function _link_in_db() { $es = new entity_selector(id_of('master_admin')); $es->add_type(id_of('admin_link')); $es->add_relation('`url` = "?cur_module=AdminTools"'); $es->set_num(1); $results = $es->run_one(); return !empty($results); }
/** * 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; }
/** * @return array of media works associated with the feature */ function get_avs_associated_with_feature($feature_id) { $es = new entity_selector(); $es->add_type(id_of('feature_type')); $es->add_left_relationship_field('feature_to_media_work', 'entity', 'id', 'av_id'); $es->enable_multivalue_results(); $es->add_relation('entity.id=' . $feature_id); $results_array = $es->run_one(); return $results_array; }
function init($args = array()) { parent::init($args); $s = new entity_selector(); $s->add_type(id_of('site')); $s->set_order('entity.name'); $s->add_relation('site.site_state = "Live"'); $this->site_count = $s->get_one_count(); $this->sites = $s->run_one(); //pray($this->sites); }
function get_available_image_galleries($site_id) { $page_types = $this->get_image_related_page_types(); $pages = array(); if (!empty($page_types)) { $es = new entity_selector($site_id); $es->add_type(id_of('minisite_page')); $es->add_relation('page_node.custom_page IN (\'' . implode('\', \'', $page_types) . '\')'); $pages = $es->run_one(); } return $pages; }
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"; } }
/** * Root finder: * Takes a site id and returns the id of the root page. * @param integer $site_id * @return mixed page id integer if found; NULL if not found */ function root_finder( $site_id ) { $es = new entity_selector( ); $es->add_type( id_of( 'minisite_page') ); $es->add_relation( 'entity.state = "Live"' ); $es->add_right_relationship( $site_id, get_owns_relationship_id(id_of('minisite_page')) ); $results = $es->run_one(); foreach( $results as $page ) { $page_id = $page->get_value( 'id' ); if( is_site_root( $page_id ) ) return $page_id; } }
/** * Determine if a site has access to the image type * @param integer $site_id site to test * @return boolean */ function site_can_manage_images($site_id) { $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_right_relationship($site_id, relationship_id_of('site_to_type')); $es->add_relation('entity.unique_name = "image"'); $es->set_num(1); $types = $es->run_one(); if (empty($types)) { return false; } else { return true; } }
function init($args = array()) { parent::init($args); // find all the sites $es = new entity_selector(); $es->description = "Getting all live sites"; $es->add_type(id_of('site')); $es->add_relation('site.site_state = "Live"'); $this->sites = $es->run_one(); // find all non-reason sites $es2 = new entity_selector(); $es2->description = 'Getting all non-reason sites'; $es2->add_type(id_of('non_reason_site_type')); $this->non_reason_sites = $es2->run_one(); }
function get_orphans($max = NULL, $refresh_cache = false) { if ($refresh_cache || !$this->_orphans_grabbed) { $e = new entity_selector(); $e->limit_tables(); $e->limit_fields(); if (empty($this->_types)) { $types = $e->run_one(id_of('type')); } else { $types = $this->_types; } $sites = $e->run_one(id_of('site'), 'All'); foreach ($types as $type_id => $type) { $e = new entity_selector(); $e->add_type($type_id); $e->limit_tables(); $e->limit_fields(); $alias = $e->add_right_relationship_field('owns', 'entity', 'id', 'site_id'); $field = $alias['site_id']['table'] . '.' . $alias['site_id']['field']; $e->add_relation($field . ' IN ("' . implode('","', array_keys($sites)) . '")'); $non_orphans = $e->run_one('', 'All'); $e = new entity_selector(); $e->add_type($type_id); $e->limit_tables(array('entity')); $e->limit_fields(); if (!empty($non_orphans)) { $e->add_relation('entity.id NOT IN ("' . implode('","', array_keys($non_orphans)) . '")'); } $orphans = $e->run_one('', 'All'); if (!empty($orphans)) { $this->_orphans[$type_id] = $orphans; if (!empty($max)) { $total = count($this->_orphans[$type_id]); $max = $max - $total; if ($max < 1) { $length = count($this->_orphans[$type_id]) + $max; $this->_orphans[$type_id] = array_slice($this->_orphans[$type_id], 0, $length, true); $this->maxed_type = array('type' => $type_id, 'total' => $total); break; } } } } } return $this->_orphans; }
function get_description($site) { $es = new entity_selector($site->id()); $es->add_type(id_of('text_blurb')); $es->add_relation('entity.name = "Site Description"'); $es->set_order('entity.last_modified DESC'); $descriptions = $es->run_one(); if (!empty($descriptions)) { reset($descriptions); $desc = current($descriptions); return $desc->get_value('content'); } elseif ($site->get_value('description')) { return $site->get_value('description'); } else { return NULL; } }
/** * @return mixed array of slot data OR false. */ function get_site_slots_with_data() { if (!isset($this->_site_slots_with_data)) { $es = new entity_selector($this->admin_page->site_id); $es->add_type(id_of('registration_slot_type')); $es->add_relation('( (registrant_data <> "") AND (registrant_data IS NOT NULL) )'); $result = $es->run_one(); if (!empty($result)) { foreach ($result as $k => $v) { $this->_site_slots_with_data[$k] = $v->get_value('name'); } } else { $this->_site_slots_with_data = FALSE; } } return $this->_site_slots_with_data; }
function set_entity_table($entity_table_name) { $es = new entity_selector($this->ma_site_id); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "' . $entity_table_name . '"'); $results = $es->run_one(); $result_count = count($results); if ($result_count == 0) { $this->err[] = 'The entity table ' . $entity_table_name . ' could not be found'; } elseif ($result_count > 1) { $this->err[] = 'Multiple entity tables were found with the name ' . $entity_table_name . ' - the script cannot be run until this is fixed.'; } elseif ($result_count == 1) { $this->entity_table_id = key($results); $this->entity_table_name = $entity_table_name; return true; } return false; }
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); } } } }
function reason_iframe_get_media_file() { if (!empty($_REQUEST['media_file_id'])) { $id = (int) $_REQUEST['media_file_id']; if ($id) { if ($work = reason_iframe_get_media_work()) { $es = new entity_selector(); $es->add_type(id_of('av_file')); $es->add_right_relationship($work->id(), relationship_id_of('av_to_av_file')); $es->add_relation('`entity`.`id` = "' . addslashes($id) . '"'); $es->set_num(1); $results = $es->run_one(); if (!empty($results)) { return current($results); } } } } return false; }
/** * Standard Module init function * * Sets up the entity selectors and grabs the site lists * * @return void */ function init() { parent::init(); $this->site = new entity($this->admin_page->site_id); $this->admin_page->title = 'Site Listing'; $lm = new entity_selector(); $lm->add_type(id_of('site')); $lm->set_order('entity.name'); $lm->add_relation('site.site_state = "Live"'); $this->ls_count = $lm->get_one_count(); $this->live_sites_list = $lm->run_one(); if (reason_user_has_privs($this->admin_page->user_id, 'view_sensitive_data')) { $nm = new entity_selector(); $nm->add_type(id_of('site')); $nm->set_order('entity.name'); $nm->add_relation('site.site_state != "Live"'); $this->nls_count = $nm->get_one_count(); $this->not_live_site_list = $nm->run_one(); } }
/** * Return published items - published items are defined as: * * 1. the news item is marked as published * 2. if the publication is issued, the news item must be related to at least one published issue * @param limit_num int set a max number of items to return from the publicaiton * @param force_refresh force a new query * * @return array news/post entities that are published */ function &get_published_items($limit_num = false, $force_refresh = false) { if ($limit_num != $this->limit) { $this->limit_changed = true; } if (!isset($this->published_items) || $this->date_changed || $this->limit_changed || $force_refresh) { $issued = $this->get_value('has_issues') == 'yes'; $issues = $issued ? $this->get_published_issues() : false; if ($issued && !$issues) { $this->published_items = array(); } else { $es = new entity_selector(); $es->description = 'Selecting published news items for this publication'; $es->add_type(id_of('news')); $es->limit_tables(array('dated', 'show_hide', 'status')); $es->limit_fields(array('dated.datetime', 'status.status', 'show_hide.show_hide')); $es->add_left_relationship($this->id(), relationship_id_of('news_to_publication')); $es->set_order('dated.datetime DESC'); if ($this->get_start_date()) { $es->add_relation('dated.datetime >= "' . $this->get_start_date() . '"'); } if ($this->get_end_date()) { $es->add_relation('dated.datetime <= "' . $this->get_end_date() . '"'); } if ($limit_num) { $es->set_num($limit_num); } $es->add_relation("status.status != 'pending'"); if ($issues) { $es->add_left_relationship_field('news_to_issue', 'entity', 'id', 'issue_id', array_keys($issues)); } $this->published_items = $es->run_one(); } $this->date_changed = false; $this->limit_changed = false; $this->limit = $limit_num; } return $this->published_items; }
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); }
function show_site($site) { $link = $site->get_value('base_url'); echo '<li>' . "\n"; echo '<h4><a href="' . $link . '">' . $site->get_value('name') . '</a></h4>' . "\n"; $es = new entity_selector($site->id()); $es->description = 'Getting pages for child site'; $es->add_type(id_of('minisite_page')); $es->add_left_relationship_field('minisite_page_parent', 'entity', 'id', 'parent_id'); $es->add_relation('page_node.nav_display = "Yes"'); $es->set_order('sortable.sort_order'); $pages = $es->run_one(); $parents = array(); foreach ($pages as $page) { if ($page->id() == $page->get_value('parent_id')) { $root_page_id = $page->id(); } else { $parents[$page->get_value('parent_id')][$page->id()] = $page; } } $this->display_pages($link, $parents, $root_page_id); echo '</li>' . "\n"; }
function display_entity() { $this->start_table(); // iFrame Preview if ($this->_entity->get_value('bug_state') != 'Done') { // iFrame Preview reason_include_once('function_libraries/URL_History.php'); $site = $this->_entity->get_owner(); $es = new entity_selector($site->id()); $es->add_type(id_of('minisite_page')); $es->add_relation('page_node.custom_page = "projects"'); $es->set_num(1); $pages = $es->run_one(); if (!empty($pages)) { $page = current($pages); $url = reason_get_page_url($page->id()) . '?item_id=' . $this->_entity->id(); $this->show_item_default('Public View of Project', '<iframe src="' . $url . '" width="100%" height="400"></iframe>'); $this->show_item_default('Link to Public View of Project', '<a href="' . $url . '">' . $url . '</a>'); } } // Everything Else $this->show_all_values($this->_entity->get_values()); $this->end_table(); }