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(); } }
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'); } }
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"; } }
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)); } } } }
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(); }
/** * 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; }
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 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); }
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')); } }
/** * 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; } } }
/** * 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]; }
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(); }
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'); }
} 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) {
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; }
function get_views($type_id) { $ds = new entity_selector(); $ds->add_type(id_of('view')); $ds->limit_tables('sortable'); $ds->limit_fields(); $ds->set_order('sortable.sort_order'); $ds->add_right_relationship($type_id, relationship_id_of('type_to_default_view')); $default_views = $ds->run_one(); $ssvs = new entity_selector(); $ssvs->add_type(id_of('view')); $ds->limit_tables('sortable'); $ds->limit_fields(); $ssvs->add_left_relationship($type_id, relationship_id_of('view_to_type')); $ssvs->add_left_relationship($this->admin_page->site_id, relationship_id_of('view_to_site')); $ssvs->set_order('sortable.sort_order'); $site_specific_views = $ssvs->run_one(); $this->views = $site_specific_views; foreach ($default_views as $id => $view) { if (!array_key_exists($id, $site_specific_views)) { $this->views[$id] = $view; } } if (!empty($this->admin_page->request['lister']) && array_key_exists($this->admin_page->request['lister'], $this->views)) { $view = $this->views[$this->admin_page->request['lister']]; if ($view->id() == $this->admin_page->request['lister']) { $viewer_type = $view->get_left_relationship('view_to_view_type'); } } elseif (!empty($this->views)) { reset($this->views); $view = current($this->views); $viewer_type = $view->get_left_relationship('view_to_view_type'); } if (!empty($viewer_type)) { reset($viewer_type); $this->viewer_entity = current($viewer_type); } }
$media_file_id = !empty($_REQUEST['media_file_id']) ? (int) $_REQUEST['media_file_id'] : 0; $media_work_id = !empty($_REQUEST['media_work_id']) ? (int) $_REQUEST['media_work_id'] : 0; $hash = !empty($_REQUEST['hash']) ? (string) $_REQUEST['hash'] : ''; if (!$media_file_id || !$media_work_id || !$hash) { http_response_code(404); die; } $media_file = new entity($media_file_id); if (!$media_file->get_values() || $media_file->get_value('type') != id_of('av_file')) { http_response_code(404); die; } # First, grab the media_work associated with the provided media file $es = new entity_selector(); $es->add_type(id_of('av')); $es->add_left_relationship($media_file->id(), relationship_id_of('av_to_av_file')); $es->add_relation('`entity`.`id` = "' . addslashes($media_work_id) . '"'); $es->add_relation('`media_work`.`integration_library` != ""'); $es->set_num(1); $works = $es->run_one(); if (empty($works)) { http_response_code(404); die; } $media_work = current($works); # check to make sure the REQUEST var hash is correct $displayer = MediaWorkFactory::media_work_displayer($media_work); if ($displayer) { $displayer->set_media_work($media_work); } else { http_response_code(404);
function display_right_relationships() { $rels = $this->get_right_relationships(); if (!empty($rels)) { $associated_items = array(); foreach ($rels as $key => $v) { $es = new entity_selector(); $es->add_type($v['relationship_a']); $es->set_env('site', $this->admin_page->site_id); $es->add_left_relationship($this->admin_page->id, $v['id']); $es->set_env('restrict_site', false); $es->add_right_relationship_field('owns', 'entity', 'name', 'owner_name'); $es->add_right_relationship_field('owns', 'entity', 'id', 'owner_id'); $ass_items = $es->run_one(); if (!empty($ass_items)) { $associated_items[$key] = $ass_items; } } if (!empty($associated_items)) { echo '<h3>Usage</h3>' . "\n"; echo '<ul>' . "\n"; foreach ($rels as $key => $v) { if (!empty($associated_items[$key])) { $is_borrows_rel = !reason_relationship_names_are_unique() ? $v['name'] == 'borrows' : $v['type'] == 'borrows'; if ($is_borrows_rel) { $type = new entity($this->_entity->get_value('type')); $title = 'Sites That Are Borrowing This ' . $type->get_value('name'); $show_owner_site = false; } else { $show_owner_site = true; $row = $this->get_rel_info($v['name']); if ($row) { $title = !empty($row['description_reverse_direction']) ? $row['description_reverse_direction'] : $row['entity_name']; } else { $title = !empty($v['description_reverse_direction']) ? $v['description_reverse_direction'] : $v['name']; } } echo '<li><h4>'; if (!$this->_entity->user_can_edit_relationship($v['id'], $this->_user, 'left')) { echo '<img class="lockIndicator" src="' . REASON_HTTP_BASE_PATH . 'ui_images/lock_12px.png" alt="Locked" width="12" height="12" />'; } elseif ($this->_entity->relationship_has_lock($v['id'], 'left') && reason_user_has_privs($this->_user->id(), 'manage_locks')) { echo '<img class="lockIndicator" src="' . REASON_HTTP_BASE_PATH . 'ui_images/lock_12px_grey_trans.png" alt="Locked for some users" title="Locked for some users" width="12" height="12" />'; } echo $title . ':</h4>' . "\n"; echo '<ul>' . "\n"; foreach ($associated_items[$key] as $ent) { echo '<li>' . $this->_get_rel_list_display_name($ent, $v['name'], 'right'); if ($show_owner_site && $ent->get_value('owner_id') != $this->admin_page->site_id) { //echo ' <em>(<a href="http://'.REASON_HOST.$ent->get_value('owner_base_url').'">'.$ent->get_value('owner_name').'</a>)</em>'; echo ' <em>(' . $ent->get_value('owner_name') . ')</em>'; } echo '</li>' . "\n"; } echo '</ul>' . "\n"; echo '</li>' . "\n"; } } echo '</ul>' . "\n"; } } }
function get_days_since_post() { $es = new entity_selector(); $es->add_type(id_of('news')); $es->add_left_relationship($this->pub->id(), relationship_id_of('news_to_publication')); $es->set_num(1); $es->set_order('datetime DESC'); $posts = $es->run_one(); if (!empty($posts)) { foreach ($posts as $id => $entity) { $this->recent_date = $entity->get_value('datetime'); } } else { return -1; } date_default_timezone_set('America/Chicago'); $date = date('Y-m-d H:i:s'); return $this->date_difference($this->recent_date, $date); }
function _get_latest_published_issue_id($blog_id) { $es = new entity_selector(); $es->add_type(id_of('issue_type')); $es->add_left_relationship($blog_id, relationship_id_of('issue_to_publication')); $es->limit_tables(array('dated', 'show_hide')); $es->set_num(1); $es->set_order('datetime DESC'); $es->add_relation('show_hide.show_hide = "show"'); $issues = $es->run_one(); if (!empty($issues)) { $issue = current($issues); return $issue->id(); } return false; }
protected function updated_media_format_definition() { $e = new entity_selector(); $e->add_type(id_of('content_table')); $e->add_relation('entity.name = "av"'); $table = current($e->run_one()); $es = new entity_selector(); $es->add_type(id_of('field')); $es->add_left_relationship($table->id(), relationship_id_of('field_to_entity_table')); $es->add_relation('entity.name = "media_format"'); $field = current($es->run_one()); return strpos(strtolower($field->get_value('db_type')), 'html5') === false ? false : true; }
function get_sites() { if (!isset($this->user_access_sites)) { $es = new entity_selector(); $es->add_type(id_of('site')); $es->add_left_relationship($this->user_id, relationship_id_of('site_to_user')); $es->set_order('entity.name ASC'); $es->limit_tables(); $es->limit_fields('entity.name'); $this->user_access_sites = $es->run_one(); } return $this->user_access_sites; }
/** * Find the subjects associated with the department associated with the current page. * * @return array of subject codes */ protected function get_site_subjects() { if (empty($this->site_subjects)) { $es = new entity_selector(); $es->description = 'Selecting department for site'; $es->add_type(id_of('office_department_type')); $es->add_left_relationship($this->site_id, relationship_id_of('office_department_has_site')); $depts = $es->run_one(); foreach ($depts as $dept_id => $dept) { $es2 = new entity_selector(); $es2->description = 'Selecting subjects for department'; $es2->add_type(id_of('subject_type')); $es2->add_right_relationship($dept_id, relationship_id_of('office_department_to_subject')); $subjects = $es2->run_one(); foreach ($subjects as $sub_id => $subject) { if ($subject->get_value('sync_name')) { $this->site_subjects[] = $subject->get_value('sync_name'); } } } } return $this->site_subjects; }
public function set_content_manager($manager) { $this->manager = $manager; // set up displayer chrome if ($this->manager->get_value('url')) { reason_include_once('classes/media/default/displayer_chrome/default.php'); $es = new entity_selector(); $es->add_type(id_of('av')); $es->add_left_relationship($manager->get_value('id'), relationship_id_of('av_to_av_file')); $media_work = current($es->run_one()); if ($media_work) { $this->displayer_chrome = new DefaultDefaultDisplayerChrome(); $this->displayer_chrome->set_media_work($media_work); $this->displayer_chrome->set_current_media_file(new entity($manager->get_value('id'))); } } }
function get_sections() { $es = new entity_selector( $this->site_info->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('entity.name ASC'); return $es->run_one(); }
/** * Move all the fields of one table into another table for a specific type * * This method is for denormalizing Reason tables. For example, a type may use a common table * like meta, datetime, or chunk. For performance reasons, it can be desirable to collapse * these tables into a single table just for that type. This method will do that. * * @param integer $type The ID of the type whose fields we are moving * @param string $source_table The name of the table we are moving fields FROM * @param string $destination_table The name of the table we are moving fields TO * @param integer $user_id The Reason ID of the user who is doing this move * @return boolean Success * * @todo Add limit to ensure fields are only created that don't already exist */ function reason_move_table_fields($type, $source_table, $destination_table, $user_id) { // Sanity checks if(empty($type)) { trigger_error('No type provided in reason_move_table_fields()'); return false; } if(empty($source_table)) { trigger_error('No source table provided in reason_move_table_fields()'); return false; } if(!is_string($source_table)) { trigger_error('Source table provided not a string in reason_move_table_fields()'); return false; } if(empty($destination_table)) { trigger_error('No destination table provided in reason_move_table_fields()'); return false; } if(!is_string($destination_table)) { trigger_error('Destination table provided not a string in reason_move_table_fields()'); return false; } if('entity' == $source_table || 'entity' == $destination_table) { trigger_error('reason_move_table_fields() cannot move fields into or out of the entity table.'); return false; } if(is_object($type)) { $type_id = $type->id(); } elseif(is_numeric($type)) { $type_id = (integer) $type; } else { $type_id = id_of($type); } if(empty($type_id)) { trigger_error('Invalid type specified in reason_move_table_fields().'); return false; } if(is_object($type)) $type_entity = $type; else $type_entity = new entity($type_id); $type_vals = $type_entity->get_values(); if(empty($type_vals)) { trigger_error('Type specified (id '.$type_id.') is not a Reason entity in reason_move_table_fields().'); return false; } if($type_entity->get_value('type') != id_of('type')) { trigger_error('Type specified (id '.$type_id.') is not a Type entity in reason_move_table_fields().'); return false; } if($type_entity->get_value('state') != 'Live') { trigger_error('Type specified (id '.$type_id.') is not a live entity in reason_move_table_fields().'); return false; } if(empty($user_id)) { trigger_error('No user id specified in reason_move_table_fields().'); return false; } $user = new entity($user_id); if(!$user->get_values() || $user->get_value('type') != id_of('user')) { trigger_error('Invalid user ID specified in reason_move_table_fields().'); return false; } // check for table existence $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('`name` = "'.addslashes($source_table).'"'); $source_table_result = $es->run_one(); if(empty($source_table_result)) { trigger_error('Source table "'.$source_table.'" does not exist in reason_move_table_fields()'); return false; } $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('`name` = "'.addslashes($destination_table).'"'); $destination_table_result = $es->run_one(); if(empty($destination_table_result)) { trigger_error('Destination table "'.$destination_table.'" does not exist in reason_move_table_fields()'); return false; } $source_table_entity = current($source_table_result); $destination_table_entity = current($destination_table_result); // ensure type uses both tables $type_tables = get_entity_tables_by_type( $type_id ); if(!in_array($source_table, $type_tables)) { trigger_error('Source table "'.$source_table.'" not part of the type in reason_move_table_fields()'); return false; } if(!in_array($destination_table, $type_tables)) { trigger_error('Destination table "'.$destination_table.'" not part of the type in reason_move_table_fields()'); return false; } $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_left_relationship($destination_table_entity->id(),relationship_id_of('type_to_table')); $es->add_relation('`entity`.`id` != "'.addslashes($type_id).'"'); $other_types = $es->run_one(); if(!empty($other_types)) { trigger_error(count($other_types).' other type(s) share the destination table with the type specified in reason_move_table_fields(). reason_move_table_fields() can only move fields into single-type tables.'); return false; } // get the fields in the old table $es = new entity_selector(); $es->add_type(id_of('field')); $es->add_left_relationship($source_table_entity->id(), relationship_id_of('field_to_entity_table')); $source_table_fields = $es->run_one(); if(empty($source_table_fields)) { trigger_error('Source table '.$source_table.' does not appear to have any fields associated with it in Reason. Unable to move its content in reason_move_table_fields()'); } $q = 'DESCRIBE `'.addslashes($destination_table).'`'; $handle = db_query( $q, 'Unable to describe destination table in reason_move_table_fields()' ); $raw_dest_cols = array(); while($row = mysql_fetch_assoc($handle)) { $raw_dest_cols[] = $row['Field']; } foreach($source_table_fields as $k=>$field) { if(in_array($field->get_value('name'),$raw_dest_cols)) { trigger_error($field->get_value('name').' field is already in destination table. Unable to accomplish reason_move_table_fields().'); return false; } $tmp_field_name = $field->get_value('name').'_move_tmp'; if(in_array($tmp_field_name,$raw_dest_cols)) { trigger_error($tmp_field_name.' field already in destination table. There appears to have been an error in a previous attempt to run reason_move_table_fields(). Please drop this column in MySQL and try again.'); return false; } $source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp'); } // Done with sanity checks // map old to temp field names & create new fields $query_parts = array(); foreach($source_table_fields as $k=>$field) { $source_table_fields[$k]->set_value('_field_move_temp_name',$field->get_value('name').'_move_tmp'); $q = 'ALTER TABLE `'.addslashes($destination_table).'` ADD '.addslashes( $field->get_value('_field_move_temp_name') ).' '. $field->get_value('db_type'); db_query( $q, 'Unable to create new field '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' ); $values = array(); foreach($field->get_values() as $f=>$v) { if($f != 'name' && $f != 'id' && strpos($f,'_') !== 0) { $values[$f] = $v; } } $id = reason_create_entity( id_of('master_admin'), id_of('field'), $user_id, $field->get_value('_field_move_temp_name'), $values); $source_table_fields[$k]->set_value('_new_field_id',$id); $query_parts[] = '`'.addslashes($destination_table).'`.`'.addslashes($field->get_value('_field_move_temp_name')).'` = `'.addslashes($source_table).'`.`'.addslashes($field->get_value('name')).'`'; } // copy content of old fields to new fields $q = 'UPDATE `'.addslashes($destination_table).'`, `'.addslashes($source_table).'`, `entity` SET '.implode(' , ',$query_parts).' WHERE `'.addslashes($destination_table).'`.`id` = `'.addslashes($source_table).'`.`id` AND `'.addslashes($destination_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'";'; db_query($q,'Attempt to move data between fields'); // zap source table's type-to-table relationship for this type $conditions = array( 'entity_a' => $type_id, 'entity_b' => $source_table_entity->id(), 'type' => relationship_id_of('type_to_table'), ); delete_relationships( $conditions ); // create new field-to-table relationship for new fields and update field names in new table -- remove temp flag foreach($source_table_fields as $field) { create_relationship( $field->get_value('_new_field_id'), $destination_table_entity->id(), relationship_id_of( 'field_to_entity_table' ) ); $q = 'ALTER TABLE `'.addslashes($destination_table).'` CHANGE '.addslashes($field->get_value('_field_move_temp_name')).' '.addslashes( $field->get_value('name') ).' '.$field->get_value('db_type') ; db_query( $q, 'Unable to change field name of '.$field->get_value('_field_move_temp_name').' in reason_move_table_fields()' ); reason_update_entity( $field->get_value('_new_field_id'), $user_id, array('name' => $field->get_value('name') ), false ); } // delete the rows from the source table $q = 'DELETE `'.addslashes($source_table).'` FROM `'.addslashes($source_table).'`, `entity` WHERE `'.addslashes($source_table).'`.`id` = `entity`.`id` AND `entity`.`type` = "'.addslashes($type_id).'"'; db_query($q,'Attempt to delete rows from '.$source_table.' in reason_move_table_fields()'); get_entity_tables_by_id( $type_id, false ); return true; }
function show_borrowing_sites($entity) { $es = new entity_selector(); $es->add_type(id_of('site')); $es->add_left_relationship($entity->id(), get_borrows_relationship_id($entity->get_value('type'))); $results = $es->run_one(); echo '<h3>Sites that borrow Entity</h3>' . "\n"; if (count($results) > 0) { echo '<table class="entityInfoTable">' . "\n"; echo '<tr>' . "\n"; echo '<th>Site Name</th>' . "\n"; echo '<th>ID #</th>' . "\n"; echo '</tr>' . "\n"; foreach ($results as $site) { echo '<tr>' . "\n"; echo '<td>' . $site->get_value('name') . '</td>' . "\n"; echo '<td>' . $this->get_id_markup($site->id()) . '</td>' . "\n"; echo '</tr>' . "\n"; } echo '</table>' . "\n"; } else { echo '<p>(none)</p>' . "\n"; } }
function run_policy_data_form($policy, $is_root) { echo '<a name="'.$policy->id().'"></a>'."\n"; $this->is_root = $is_root; $this->edit_policy = $policy; $form = new Disco(); $form->strip_tags_from_user_input = true; $form->allowable_HTML_tags = REASON_DEFAULT_ALLOWED_TAGS; $form->actions = array('save' => 'Save', 'save_and_finish' => 'Save and Finish Editing'); $this->init_field($form, 'name', $policy, 'text', 'solidtext'); $form->set_value('name', $policy->get_value('name')); $form->set_display_name('name', 'Title'); $form->add_required('name'); if ($this->is_root) { $this->init_field($form, 'description', $policy, 'text', 'solidtext'); $form->set_value('description', $policy->get_value('description')); } //$form->add_element('content', html_editor_name($this->site_id), html_editor_params($this->site_id, $this->get_html_editor_user_id())); $this->init_field($form, 'content', $policy, html_editor_name($this->site_id), 'wysiwyg_disabled', html_editor_params($this->site_id, $this->get_html_editor_user_id())); $form->set_value('content', $policy->get_value('content')); $form->set_display_name('content', 'Section Content'); $sub_policies = $this->get_policy_children($policy); if (!empty($sub_policies)) { // Populate the numbering_scheme elements $es = new entity_selector(); $es->add_type(id_of('content_table')); $es->add_relation('entity.name = "policies"'); $policy_table = current($es->run_one()); unset($es); $es = new entity_selector(); $es->add_type( id_of('field') ); $es->add_left_relationship($policy_table->id(), relationship_id_of('field_to_entity_table')); $es->add_relation('entity.name = "numbering_scheme"'); $field = current($es->run_one()); $args = array(); $type = ''; // set the plasmature type if specified by the field, otherwise look up the default for the database type list( $type, $args ) = $form->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 //$form->add_element('numbering_scheme', $type, $args, $field->get_value('db_type')); $this->init_field($form, 'numbering_scheme', $policy, $type, 'solidtext', $args); $form->set_value('numbering_scheme', $policy->get_value('numbering_scheme')); $form->set_display_name('numbering_scheme', 'Sub-Policy Numbering Style'); } $form->add_callback(array(&$this, '_process_policy'),'process'); $form->add_callback(array(&$this, '_where_to_policy'), 'where_to'); $form->run(); }
function get_item_events($item) { $es = new entity_selector(); $es->set_env( 'site' , $this->site_id ); $es->description = 'Selecting events for this news item'; $es->add_type( id_of('event_type') ); $es->add_left_relationship( $item->id(), relationship_id_of('event_to_news') ); $es->add_rel_sort_field( $item->id(), relationship_id_of('event_to_news') ); $es->set_order('rel_sort_order'); $events = $es->run_one(); if (!empty($events)) { $base_url = $this->get_events_page_url(); foreach(array_keys($events) as $id) { $url = $base_url; if(!empty($url)) { $url .= '?event_id='.$id; if($this->textonly) $url .= '&textonly=1'; } $events[$id]->set_value('event_url',$url); } } return $events; }
} if ($pub->get_value('type') != id_of('publication_type')) { die('The publication provided is not, in fact, a publication' . "\n"); } $days = (int) $args['days']; if (empty($days)) { die('Please provide days as an integer (e.g. 1, 2, 3, or 73)' . "\n"); } $time = strtotime('-' . $days . ' days'); if (empty($time)) { die('Something appears to be amiss -- no time value was able to be resolved from the number of days provided' . "\n"); } $datetime = date('Y-m-d H:i:s', $time); $es = new entity_selector(); $es->add_type(id_of('news')); $es->add_left_relationship($pub->id(), relationship_id_of('news_to_publication')); $es->add_relation('`datetime` >= "' . $datetime . '"'); $es->set_num(1); $posts = $es->run_one(); if (empty($posts)) { echo 'No new posts on publication id ' . $pub->id() . ' (' . $pub->get_value('name') . ') since ' . $datetime . '.' . "\n"; if (!empty($args['emails'])) { $message = 'FYI, there are currently no recent posts on the Reason publication "' . $pub->get_value('name') . '."' . "\n\n"; $message .= 'You are signed up to receive notices when this publication has not been updated in the last ' . $days . ' days.' . "\n\n"; $message .= 'It may be time to add a new post!' . "\n\n"; $message .= 'Click here to add posts to this publication: http://' . REASON_WEB_ADMIN_PATH . '?site_id=' . get_owner_site_id($pub->id()) . '&type_id=' . id_of('news') . "\n\n"; $message .= 'If you are no longer responsible for this publication, please contact a Reason administrator to have this email sent to someone else.' . "\n\n"; $message .= 'Thank you!' . "\n\n"; mail($args['emails'], 'Reason Publication Reminder', $message, 'From: <*****@*****.**>'); echo 'Message sent to ' . $args['emails'] . "\n"; }