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 process() { //prep site $this->helper->ensure_type_is_on_site(id_of('publication_type')); $this->helper->ensure_type_is_on_site(id_of('group_type')); $this->helper->ensure_nobody_group_is_on_site(); // gather core information $pub_type_id = id_of('publication_type'); $name = trim(strip_tags($this->get_value('pub_name'))); // populate values array $values['new'] = 0; $values['description'] = trim(get_safer_html($this->get_value('pub_description'))); $values['unique_name'] = trim(strip_tags($this->get_value('pub_unique_name'))); $values['state'] = 'Live'; $values['hold_comments_for_review'] = 'no'; $values['posts_per_page'] = turn_into_int($this->get_value('pub_posts_per_page')); $values['blog_feed_string'] = trim(strip_tags($this->get_value('pub_rss_feed_url'))); $values['publication_type'] = 'Newsletter'; $values['has_issues'] = 'no'; $values['has_sections'] = 'no'; $values['date_format'] = $this->get_value('date_format'); // create the publication $pub_id = reason_create_entity($this->site_id, $pub_type_id, $this->user_id, $name, $values); // associate with nobody posting and commenting groups create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_posting_group')); create_relationship($pub_id, id_of('nobody_group'), relationship_id_of('publication_to_authorized_commenting_group')); }
/** * Determines whether or not the current user has access to the specified media work. If no username is provided, this function defaults to the currently-loggin-in username. * * @param string $username * @return boolean user has access */ public function user_has_access_to_media($username = '') { // First, get the restricted group--if one exists $es = new entity_selector(); $es->add_type(id_of('group_type')); $es->add_right_relationship($this->media_work->id(), relationship_id_of('av_restricted_to_group')); $group = current($es->run_one()); if (!empty($group)) { $gh = new group_helper(); $gh->set_group_by_id($group->id()); if ($gh->requires_login()) { if (!$username) { $username = reason_check_authentication(); } if ($username) { if (!$gh->is_username_member_of_group($username)) { return false; } } else { return false; } } } return true; // Return true if the user has access to view media work }
/** * Make sure that the model is configured with a valid URL. * * @return string json */ function build() { if ($site_id = $this->config('site_id')) { $s = get_microtime(); $es = new entity_selector(); $es->add_type(id_of('social_account_type')); $es->add_right_relationship($site_id, relationship_id_of('site_to_social_account')); $es->add_rel_sort_field($site_id, relationship_id_of('site_to_social_account')); $es->set_order('rel_sort_order ASC'); $es->limit_tables(); $es->limit_fields(); if ($results = $es->run_one()) { $result_keys = array_keys($results); $sih = reason_get_social_integration_helper(); foreach ($result_keys as $id) { // get the integrator if it supports the SocialAccountProfileLinks interface if ($integrator = $sih->get_social_account_integrator($id, 'SocialAccountProfileLinks')) { $profile_links[$id]['icon'] = $integrator->get_profile_link_icon($id); $profile_links[$id]['text'] = $integrator->get_profile_link_text($id); $profile_links[$id]['href'] = $integrator->get_profile_link_href($id); } } if (!empty($profile_links)) { return $profile_links; } } return false; } else { trigger_error('The ReasonSocialProfileLinksModel must be provided with the configuration parameter site_id.', FATAL); } }
protected function link_section_to_parent($section) { //echo round(memory_get_usage()/1024,2)."K at point A\n"; if ($template = $this->get_section_parent($section->get_value('parent_template_id'))) { // echo round(memory_get_usage()/1024,2)."K at point B\n"; if (!($parents = $section->get_right_relationship('course_template_to_course_section'))) { return create_relationship($template->id(), $section->id(), relationship_id_of('course_template_to_course_section'), false, false); } else { if (is_array($parents)) { $current_template = reset($parents); // echo round(memory_get_usage()/1024,2)."K at point C\n"; // verify that we have the correct parent, and fix if not. if ($current_template->get_value('sourced_id') == $template->get_value('sourced_id')) { return true; } else { //$this->errors[] = 'Incorrect template attached to '.$section->get_value('name'); echo 'Incorrect template attached to ' . $section->get_value('name'); } } else { //$this->errors[] = 'Non-array '.$parents.' returned from get_right_relationship'; echo 'Non-array ' . $parents . ' returned from get_right_relationship'; } } } else { //$this->errors[] = 'No template found for '.$section->get_value('name'); echo 'No template found for ' . $section->get_value('name'); return false; } }
function init($args = array()) { parent::init($args); /* $es = new entity_selector( $this->parent->site_id ); $es->add_type( id_of( 'policy_type' ) ); //$es->set_order( 'sortable.sort_order ASC' ); $es->set_order( 'entity.name ASC' ); $es->add_left_relationship_field( 'parent' , 'entity' , 'id' , 'parent_id' ); $es->add_right_relationship( $this->parent->cur_page->id(), relationship_id_of('page_to_policy') ); $this->values = $es->run_one(); */ //$this->pages->order_by = 'sortable.sort_order ASC'; //Set up our AllPolicyNavigation to grab all the policies associated //with a given page and sort them by sort_order. //I am not really sure how necessary it is to use a mutiple_root_tree_viewer, //but it works. $this->pages = new AllPolicyNavigation(); $this->pages->init($this->parent->site_id, id_of('policy_type')); $this->pages->es->set_order('sortable.sort_order ASC'); $this->pages->es->add_left_relationship_field('policy_parent', 'entity', 'id', 'parent_id'); $this->pages->es->add_right_relationship($this->parent->cur_page->id(), relationship_id_of('page_to_policy')); $this->pages->values = $this->pages->es->run_one(); //$this->pages->request =& $this->request; //I don't think this kludge is required for this usage, so I am commenting it out //Just in case, though, I am leaving it in the code. JLO 03/10/04 // small kludge - just give the tree view access to the site info. used in the show_item function to show the root node of the navigation //if ( !empty ( $this->site_info ) ) // $this->pages->site_info = $this->site_info; }
function get_links() { $links = parent::get_links(); $es = new entity_selector($this->admin_page->site_id); $es->add_type(id_of('event_type')); $es->set_order('dated.datetime DESC'); $values = $es->run_one(); //should adjust so that can't rearrange slots for events that have only one or no registration slots. //also, probably not for past events either. if ($values) { foreach ($values as $event_id => $event) { $es2 = new entity_selector($this->admin_page->site_id); $es2->add_type(id_of('registration_slot_type')); $es2->add_right_relationship($event_id, relationship_id_of('event_type_to_registration_slot_type')); $numSlots = $es2->get_one_count(); if ($numSlots > 1) { $date = $event->get_value('datetime'); $name = 'Sort slots for ' . $event->get_value('name') . ' - ' . prettify_mysql_datetime($date); $link = $this->admin_page->make_link(array('event_id' => $event->id(), 'default_sort' => false), true); $links[$name] = $link; } } $this->links = $links; return $this->links; } }
function alter_es() // {{{ { if (!$this->params['limit_to_current_site']) { $alias = $this->es->add_right_relationship_field('owns', 'entity', 'name', 'site_name'); $site_order_string = $alias['site_name']['table'] . '.' . $alias['site_name']['field'] . ' ASC'; $this->es->set_order( $site_order_string . ', entity.last_modified DESC' ); } else { $this->es->set_order( 'entity.last_modified DESC' ); } if(!empty($this->params['audiences'])) { $aud_ids = array(); foreach($this->params['audiences'] as $audience) { $aud_id = id_of($audience); if($aud_id) { $aud_ids[] = $aud_id; } else { trigger_error($audience.' is not a unique name; skipping this audience'); } } if(!empty($aud_ids)) { $this->es->add_left_relationship($aud_ids, relationship_id_of('faq_to_audience')); } } } // }}}
protected function _rel_is_sortable() { if ($info = reason_get_allowable_relationship_info(relationship_id_of('event_to_image'))) { return $info['is_sortable'] == 'yes' ? true : false; } trigger_error('unable to find event_to_image allowable relationship'); }
protected function _get_es() { $es = parent::_get_es(); $es->set_site(null); $es->add_right_relationship($this->page_id, relationship_id_of('page_to_policy')); return $es; }
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 alter_data() { $this->set_display_name('name', 'Section Name'); $this->remove_element('keywords'); $this->add_relationship_element('publication', id_of('publication_type'), relationship_id_of('news_section_to_publication'), 'right', 'select'); //$this->add_required('publication'); $this->set_order(array('publication', 'name')); }
function refine_es($es) { $es->add_right_relationship($this->page_id, relationship_id_of('minisite_page_to_image')); $es->add_rel_sort_field($this->page_id, relationship_id_of('minisite_page_to_image'), 'rel_sort_order'); // order first by rel_sort_order if that is not defined second criteria is dated.datetime ASC - this keeps pages that change to gallery pages reasonably predictable $es->set_order('rel_sort_order ASC, dated.datetime ASC'); return $es; }
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 get_minisite_template($theme_id) { $template = false; $es = new entity_selector(); $es->add_type(id_of('minisite_template')); $es->add_right_relationship($theme_id, relationship_id_of('theme_to_minisite_template')); $tmp = $es->run_one(); return current($tmp); }
function process() { $pub_id = $this->get_value('publication_id'); $issues_to_link = $this->get_value('issues'); foreach ($issues_to_link as $issue_id) { create_relationship($issue_id, $pub_id, relationship_id_of('issue_to_publication')); } // update the publication - set has_issues to "Yes" reason_update_entity($pub_id, $this->user_id, array('has_issues' => 'yes')); }
function is_site_root( $page_id ) { $query = 'SELECT * FROM relationship WHERE entity_a="' . addslashes($page_id) . '" AND type="' . relationship_id_of( 'minisite_page_parent' ) . '"'; $results = db_query( $query ); while( $row = mysql_fetch_array( $results ) ) { if( $row['entity_b'] == $page_id ) return true; } return false; }
function run() { $site_id = $this->site_id; $es = new entity_selector($site_id); $es->add_type(id_of('google_map_type')); $es->add_right_relationship($this->cur_page->id(), relationship_id_of('page_to_google_map')); $es->add_rel_sort_field($this->cur_page->id(), relationship_id_of('page_to_google_map')); $es->set_order('rel_sort_order'); $gmaps = $es->run_one(); draw_google_map($gmaps); }
function get_av_files($item, $num = 0) { $avf = new entity_selector(); $avf->add_type(id_of('av_file')); $avf->add_right_relationship($item->id(), relationship_id_of('av_to_av_file')); $avf->set_order('av.media_format ASC, av.av_part_number ASC'); if ($num) { $avf->set_num($num); } return $avf->run_one(); }
/** * Initialize the module * grabs all the blurbs associated with the current site * @param $args array */ function init($args = array()) { parent::init($args); $master_admin_id = id_of('master_admin'); $es = new entity_selector($master_admin_id); $es->limit_tables(); $es->limit_fields(); $es->add_type(id_of('text_blurb')); $es->add_right_relationship($this->site_id, relationship_id_of('site_to_announcement_blurb')); $es->set_env('site', $master_admin_id); $this->blurbs = $es->run_one(); }
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 init($args = array()) { $es = new entity_selector($this->parent->site_id); $es->description = 'Selecting blog/publications for this page'; $es->add_type(id_of('publication_type')); $es->add_right_relationship($this->parent->cur_page->id(), relationship_id_of('page_to_publication')); $es->set_num(1); $blogs = $es->run_one(); if (!empty($blogs)) { $this->blog = current($blogs); } }
function process() { $pub_id = $this->get_value('publication_id'); $sections_to_link = $this->get_value('sections'); foreach ($sections_to_link as $section_id) { create_relationship($section_id, $pub_id, relationship_id_of('news_section_to_publication')); // old style news would show as many items per section as existed ... we will set the posts_per_section_on_front_page to 1000 // to make sure the publication continues to behave the same way ... not exactly pretty but it works for now. reason_update_entity($section_id, $this->user_id, array('posts_per_section_on_front_page' => 1000)); } // update the publication - set has_sections to "Yes" reason_update_entity($pub_id, $this->user_id, array('has_sections' => 'yes')); }
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(); }
/** * Check if the current site has the registration slot type. */ function site_has_slot_type() { if (!isset($this->_site_has_slot_type)) { $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_right_relationship($this->admin_page->site_id, relationship_id_of('site_to_type')); $es->add_relation('entity.id = "' . id_of('registration_slot_type') . '"'); $es->set_num(1); $result = $es->run_one(); $this->_site_has_slot_type = !empty($result); } return $this->_site_has_slot_type; }
/** * 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 alter_es() { if ($this->params['sort_order'] == 'rel') { $this->es->add_rel_sort_field($this->page_id, relationship_id_of('minisite_page_to_image'), 'rel_sort_order'); $this->es->set_order('rel_sort_order ASC, dated.datetime ASC, meta.description ASC, entity.id ASC'); } else { $this->es->set_order($this->params['sort_order']); } if ($this->params['max_num']) { $this->es->set_num($this->params['max_num']); } $this->es->set_env('site', $this->site_id); $this->es->add_right_relationship($this->page_id, relationship_id_of('minisite_page_to_image')); }
function init() { parent::init(); $this->admin_page->title = 'Download Links for Media Work'; $this->media_work = new entity($this->admin_page->id); if ($this->media_work->get_value('integration_library') == 'kaltura') { $this->kaltura_shim = new KalturaShim(); $this->user = new entity($this->admin_page->user_id); // Grab the associated media files $es = new entity_selector(); $es->add_type(id_of('av_file')); $es->add_right_relationship($this->media_work->id(), relationship_id_of('av_to_av_file')); $this->media_files = $es->run_one(); } }
/** * Run the upgrader * @return string HTML report */ public function run() { if ($this->_link_in_db()) { return 'This script has already run'; } else { if ($id = reason_create_entity(id_of('master_admin'), id_of('admin_link'), $this->user_id(), 'Admin Tools', array('url' => '?cur_module=AdminTools', 'new' => 0))) { if (create_relationship(id_of('master_admin'), $id, relationship_id_of('site_to_admin_link'))) { return 'Created the admin tools link and placed on Master Admin sidebar'; } else { return 'Created the admin tools link but error occurred placing in Master Admin sidebar. You may want to do this manually.'; } } else { return 'Error creating the AdminTools link. You may want to add this link manually, by adding an Admin Link in Master Admin to the URL "?cur_module=AdminTools"'; } } }
function get_form() { if (!isset($this->_form)) { $this->_form = false; // Get the form entity attached to the current page $es = new entity_selector(); $es->add_type(id_of('form')); $es->add_right_relationship($this->cur_page->id(), relationship_id_of('page_to_form')); $es->set_num(1); $result = $es->run_one(); if ($result) { $this->_form = reset($result); } } return $this->_form; }