Esempio n. 1
0
 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 &amp; 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;
 }
 /**
  * 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);
     }
 }
Esempio n. 4
0
 function get_last_modified_item_selector()
 {
     $es = new entity_selector($this->site_id());
     $es->add_type($this->type());
     $es->limit_tables();
     $es->limit_fields('last_modified');
     $es->set_num(1);
     $es->set_order('last_modified DESC');
     return $es;
 }
 /**
  * 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 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;
 }
Esempio n. 7
0
 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);
             }
         }
     }
 }
Esempio n. 8
0
 /**
  * If the current site has the publication type, find the feed url for the oldest publication and redirect
  */
 function publication_check($site)
 {
     $es = new entity_selector($site->id());
     $es->add_type(id_of('publication_type'));
     $es->add_right_relationship_field('news_to_publication', 'entity', 'id', 'news_id');
     $es->limit_tables('entity');
     $es->limit_fields('entity.creation_date');
     $es->set_num(1);
     $es->set_order('entity.creation_date ASC');
     $result = $es->run_one();
     if ($result) {
         $id_array = array_keys($result);
         $ph = new publicationHelper(reset($id_array));
         // should I bother with the helper or just do it here?
         $feed_url = $ph->get_feed_url($site->id());
         if ($feed_url) {
             header("Location: " . $feed_url, true, 301);
         }
     }
 }
Esempio n. 9
0
 /**
  * Get the groups that apply to a given page
  * @param integer $page_id
  * @return array of group objects
  */
 function get_groups($page_id)
 {
     if (!isset($this->_pages_to_groups[$page_id])) {
         $alrel_id = relationship_id_of('page_to_access_group');
         if (!$alrel_id) {
             trigger_error('page_to_access_group needs to be added. Please upgrade your database at ' . REASON_HTTP_BASE_PATH . 'scripts/upgrade/4.0b6_to_4.0b7/');
             return array();
         }
         $chain = $this->_page_tree->get_id_chain($page_id);
         if (empty($chain)) {
             trigger_error('Page ' . $page_id . 'does not appear to be in site.');
             $this->_pages_to_groups[$page_id] = array();
         } else {
             $es = new entity_selector();
             $es->add_type(id_of('group_type'));
             $es->limit_tables();
             $es->limit_fields();
             $es->add_right_relationship($chain, $alrel_id);
             $es->set_num(count($chain));
             $this->_pages_to_groups[$page_id] = $es->run_one();
         }
     }
     return $this->_pages_to_groups[$page_id];
 }
function build_entities($e, $t, $last_edited_by, &$entities)
{
    global $a_ids;
    $cb_new = '';
    if ($rel_id = isset($a_ids[$t]) ? $a_ids[$t] : false) {
        $es = new entity_selector();
        $es->add_type($t);
        $es->add_right_relationship($e, $rel_id);
        $es->limit_fields(array('entity.last_edited_by'));
        $es->limit_tables(array('entity'));
        $es->set_order('last_modified ASC, entity.id ASC');
        $archived = $es->run_one(false, 'Archived');
        foreach ($archived as $k => $v) {
            if (empty($cb_new)) {
                $result = true;
                $cb_new = $v->get_value('last_edited_by');
                $entities[$e] = $cb_new;
            }
            $entities[$k] = $cb_new;
        }
    }
    return isset($result);
}
Esempio n. 11
0
 function init_from_categories(&$already_selected)
 {
     if ($this->page_category_mode) {
         $cat_es = new entity_selector($this->site_id);
         $cat_es->add_type(id_of('category_type'));
         $cat_es->limit_tables();
         $cat_es->limit_fields();
         $cat_es->add_right_relationship($this->page_id, relationship_id_of('page_to_category'));
         $cat_result = $cat_es->run_one();
         if (!empty($cat_result)) {
             $es = new entity_selector($this->site_id);
             $es->add_type(id_of('quote_type'));
             $es->set_env('site', $this->site_id);
             $es->add_left_relationship_field('quote_to_category', 'entity', 'id', 'cat_id', array_keys($cat_result));
             if (!empty($already_selected)) {
                 $es->add_relation('entity.id NOT IN (' . implode(array_keys($already_selected)) . ')');
             }
             $result = $es->run_one();
         }
     }
     return !empty($result) ? $result : array();
 }
 /**
  * Find all files with one of these extensions .pptx, .docx, or xlsx where mime type is not application/vnd.openxmlformats
  *
  * @todo implement me
  */
 protected function get_assets_needing_fixing()
 {
     $es = new entity_selector();
     $es->limit_tables(array('entity', 'asset'));
     $es->limit_fields(array('mime_type', 'file_type', 'last_edited_by', 'last_modified'));
     $es->add_type(id_of('asset'));
     $es->add_relation('`file_type` IN ("' . implode('","', $this->seek_file_extensions) . '")');
     $es->add_relation('`mime_type` IN ("' . implode('","', $this->seek_mime_types) . '")');
     $result = $es->run_one();
     return !empty($result) ? $result : FALSE;
 }
<input type="submit" name="do_it" value="Run the script" />
</form>
<?php 
} else {
    $report = '';
    // first find all sites
    $es = new entity_selector();
    $es->add_type(id_of('site'));
    $es->limit_tables();
    $es->limit_fields();
    $result = $es->run_one();
    $site_ids = array_keys($result);
    foreach ($site_ids as $site_id) {
        $es = new entity_selector($site_id);
        $es->add_type(id_of('minisite_page'));
        $es->limit_tables();
        $es->limit_fields();
        $meta = $es->add_left_relationship_field('minisite_page_parent', 'entity', 'id', 'parent_id');
        $str = $meta['parent_id']['table'] . "." . $meta['parent_id']['field'];
        $es->add_relation('entity.id = ' . $str);
        $result = $es->run_one();
        $count = count($result);
        if ($count > 1) {
            $site = new entity($site_id);
            $report .= '<h3>The site "' . $site->get_value('name') . '" has ' . $count . ' root pages.</h3>';
            $report .= '<ul>';
            foreach ($result as $page) {
                $last_mod = $page->get_value('last_modified');
                $page_name = $page->get_value('name');
                $page_name = !empty($page_name) ? $page_name : '<em>Untitled</em>';
                $report .= '<li>' . $page_name . ' (id is ' . $page->id() . ', last modified ' . prettify_mysql_datetime($last_mod) . ')</li>';
Esempio n. 14
0
		function further_checks_on_entity( $entity )
		{
			if($this->params['limit_to_current_page'])
			{
				$es = new entity_selector();
				$es->add_type(id_of('av'));
				$es->add_relation('`entity`.`id` = "'.addslashes($entity->id()).'"');
				$es->add_right_relationship( $this->page_id, relationship_id_of('minisite_page_to_av') );
				$es->set_num(1);
				$es->limit_tables();
				$es->limit_fields();
				$results = $es->run_one();
				return (!empty($results));
			}
			return true;
		}
Esempio n. 15
0
	function get_allowable_relationships_with_missing_types()
	{
		$es = new entity_selector();
		$es->limit_tables();
		$es->limit_fields(array('id', 'name'));
		$es->add_type(id_of('type'));
		$valid_types = $es->run_one('', 'All'); // look at all entities of all state
		$valid_type_ids = implode(',', array_keys($valid_types));
		
		$q = 'SELECT id from allowable_relationship WHERE ((relationship_a NOT IN ('.$valid_type_ids.')) OR
														   (relationship_b NOT IN ('.$valid_type_ids.')))';
		$results = db_query($q);
		while ($result = mysql_fetch_assoc($results))
		{
			$ids[] = $result['id'];
		}
		return (isset($ids)) ? $ids : array();
	}
Esempio n. 16
0
 function &_get_site_pages_with_valid_publications()
 {
     $rpts =& get_reason_page_types();
     $ms =& reason_get_module_sets();
     $publication_modules = $ms->get('publication_item_display');
     $page_types = $rpts->get_page_type_names_that_use_module($publication_modules);
     // this logic to exclude publication page types with related mode set to true is a bit silly.
     // perhaps we should have in the page types class something that lets us filter a set of page types according to parameter values or something
     foreach ($page_types as $page_type_name) {
         $pt = $rpts->get_page_type($page_type_name);
         $pt_props = $pt->get_properties();
         foreach ($pt_props as $region => $region_info) {
             if (in_array($region_info['module_name'], $publication_modules) && !(isset($region_info['module_params']['related_mode']) && ($region_info['module_params']['related_mode'] == "true" || $region_info['module_params']['related_mode'] == true))) {
                 $valid_page_types[] = $page_type_name;
             }
         }
     }
     if (isset($valid_page_types)) {
         // check each page type to make sure publication is NOT in related mode
         foreach (array_keys($valid_page_types) as $k) {
             quote_walk($valid_page_types[$k], NULL);
         }
         $es = new entity_selector($this->site->id());
         $es->add_type(id_of('minisite_page'));
         $es->limit_tables(array('page_node'));
         $es->limit_fields(array('custom_page'));
         $es->add_left_relationship_field('page_to_publication', 'entity', 'id', 'pub_id');
         $es->add_relation('page_node.custom_page IN (' . implode(",", $valid_page_types) . ')');
         $result = $es->run_one();
     } else {
         $result = false;
     }
     return $result;
 }
	function _validate_thor_tables($all_tables)
	{
		// create string of ids
		$form_ids = array_keys($all_tables);
		$form_id_string = implode(",",$form_ids);
		
		// select all form entities with ids in $all_tables - ones that are not selected do not correspond to a reason entity
		$es = new entity_selector();
		$es->add_type(id_of('form'));
		$es->limit_tables();
		$es->limit_fields();
		$es->add_relation('entity.id IN ('.$form_id_string.')');
		$result = $es->run_one();
		$form_ids_in_reason = array_keys($result);
		$invalid_ids = (array_diff($form_ids, $form_ids_in_reason));
		foreach ($invalid_ids as $id)
		{
			unset($all_tables[$id]);
		}
		return $all_tables;
	}
 function &get_sites()
 {
     if (!isset($this->_sites)) {
         $es = new entity_selector();
         $es->limit_tables();
         $es->limit_fields('entity.name');
         $es->add_type(id_of('site'));
         $es->set_order('entity.name ASC');
         $this->_sites = $es->run_one();
     }
     return $this->_sites;
 }
Esempio n. 19
0
 /**
  * We want to find pages where custom_page is in our array $deleted_page_type_names_to_check_for.
  *
  */
 protected function get_pages_using_now_missing_page_types()
 {
     static $retrieved;
     if (!isset($retrieved)) {
         $es = new entity_selector();
         $es->limit_tables('page_node');
         $es->limit_fields('custom_page');
         $es->add_type(id_of('minisite_page'));
         $es->add_relation('page_node.custom_page IN ("' . implode('","', $this->deleted_page_type_names_to_check_for) . '")');
         $retrieved = $es->run_one();
     }
     return $retrieved;
 }
Esempio n. 20
0
 function site_owns_id()
 {
     if ($this->id && $this->site_id && empty($this->request['new_entity']) && $this->cur_module && ($this->cur_module == 'Editor' || $this->cur_module == 'Associator')) {
         $es = new entity_selector($this->site_id);
         $es->add_type($this->type_id);
         $es->limit_tables();
         $es->limit_fields();
         $es->add_relation('entity.id = ' . $this->id);
         $es->set_sharing('owns');
         $es->set_num(1);
         if ($es->run_one('', 'All')) {
             return true;
         } else {
             return false;
         }
     }
     return true;
 }
Esempio n. 21
0
 /**
  * Find the categories attached to the current page.
  *
  * @return array of categories (id => name)
  */
 protected function get_page_categories()
 {
     if (empty($this->page_categories)) {
         $cat_es = new entity_selector();
         $cat_es->description = 'Selecting categories for this page';
         $cat_es->add_type(id_of('category_type'));
         $cat_es->limit_tables();
         $cat_es->limit_fields();
         $cat_es->add_right_relationship($this->get_source_page_id(), relationship_id_of('page_to_category'));
         if ($categories = $cat_es->run_one()) {
             foreach ($categories as $cat) {
                 $this->page_categories[$cat->id()] = $cat->get_value('name');
             }
         }
     }
     return $this->page_categories;
 }
Esempio n. 22
0
		function get_page_image($page_id)
		{
			$es = new entity_selector();
			$es->set_env( 'site' , $this->site_id );
			$es->add_type(id_of('image'));
			$es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image'));
			$es->set_num(1);
			$es->limit_tables();
			$es->limit_fields();
			if($this->params['randomize_images']) $es->set_order('rand()');
			else $es->set_order('relationship.rel_sort_order ASC');
			$images = $es->run_one();
			if(!empty($images))
			{
				return current($images);
			}
			return false;
		}
Esempio n. 23
0
 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;
 }
Esempio n. 24
0
 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;
 }
Esempio n. 25
0
/**
 * 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];
}
Esempio n. 26
0
		/**
		* Returns an array of the issues associated with the current item id.
		* Format: $issue_id => $issue_entity
		* @return array array of the issues for this publication
		*/
		function &get_issues_for_item()
		{
			static $issues;
			if (!isset($issues[$this->current_item_id]))
			{
				if ($all_issues = $this->get_all_issues())
				{
					$es = new entity_selector( $this->site_id );
					$es->description = 'Selecting issues for this news item';
					$es->limit_tables('dated');
					$es->limit_fields('dated.datetime');
					$es->add_type( id_of('issue_type') );
					$es->add_right_relationship( $this->current_item_id, relationship_id_of('news_to_issue') );
					$es->add_relation('entity.id IN ('.implode(", ", array_keys($all_issues)).')');
					$es->set_order('dated.datetime DESC');
					$issue_set = $es->run_one();
					$issues[$this->current_item_id] = $issue_set;
				}
				else $issues[$this->current_item_id] = FALSE;
			}
			return $issues[$this->current_item_id];
		}
Esempio n. 27
0
 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);
     }
 }
Esempio n. 28
0
/**
 * If the enable_comment_notification field exists, then zap it - will only be the case if an earlier version of this script was run
 *
 */
function zap_field($entity_table_name, $field_name, $reason_user_id)
{
    $es = new entity_selector();
    $es->add_type(id_of('content_table'));
    $es->add_relation('entity.name = "' . $entity_table_name . '"');
    $es->set_num(1);
    $es->limit_tables();
    $es->limit_fields();
    $result = $es->run_one();
    if (empty($result)) {
        echo '<p>The entity table ' . $entity_table_name . ' does not exist - field ' . $field_name . ' could not be zapped</p>';
        return false;
    } else {
        $et = current($result);
        $es2 = new entity_selector();
        $es2->add_type(id_of('field'));
        $es2->add_relation('entity.name = "' . $field_name . '"');
        $es2->add_left_relationship($et->id(), relationship_id_of('field_to_entity_table'));
        $es2->set_num(1);
        //$es2->limit_tables();
        //$es2->limit_fields();
        $result2 = $es2->run_one();
        if (empty($result2)) {
            echo '<p>The field ' . $field_name . ' does not exist in entity table ' . $entity_table_name . ' and could not be zapped</p>';
            return false;
        } else {
            $res = current($result2);
            $q = "ALTER TABLE " . $entity_table_name . " DROP " . $field_name;
            db_query($q);
            reason_expunge_entity($res->id(), $reason_user_id);
            // also deletes all relationships to the field, which fixes the entity table
            echo '<p>Zapped field ' . $field_name . ' in entity table ' . $entity_table_name . '<p>';
        }
    }
}
Esempio n. 29
0
 function get_assets()
 {
     if (!isset($this->_assets)) {
         $es = new entity_selector($this->config('site_id'));
         $es->add_type(id_of('asset'));
         $es->limit_tables();
         $es->limit_fields('name');
         $this->_assets = $es->run_one();
     }
     return $this->_assets;
 }
 /**
  * Move the field location in the location entity table to the event table and then delete the location entity table. 
  */
 function move_location_field_to_event()
 {
     $fields = get_fields_by_content_table('event');
     if (in_array('location', $fields)) {
         echo '<p>The event entity table already has the location field - the script has probably been run</p>';
         $es = new entity_selector();
         $es->add_type(id_of('event_type'));
         $es->set_num(5);
         $es->add_relation('event.location IS NOT NULL');
         $result = $es->run_one();
     } elseif ($this->mode == 'run') {
         // grab all locations from the location.location table for events
         $es = new entity_selector();
         $es->add_type(id_of('event_type'));
         $es->limit_tables(array('location'));
         $es->limit_fields(array('location.location'));
         $es->add_relation(' ((location.location IS NOT NULL) AND (location.location != ""))');
         $result = $es->run_one('', 'All');
         // All does not get archived entities ... hmmm
         $result2 = $es->run_one('', 'Archived');
         // populate $ids - an array of entity ids to location value, with it we can do a direct update of the event entity table
         foreach ($result as $k => $v) {
             $ids[$k] = $v->get_value('location');
         }
         foreach ($result2 as $k2 => $v2) {
             $ids[$k2] = $v2->get_value('location');
         }
         unset($es);
         unset($result);
         unset($result2);
         // lets find our table entity
         $es = new entity_selector();
         $es->add_type(id_of('content_table'));
         $es->add_relation('entity.name = "location"');
         $es->set_num(1);
         $location_result = $es->run_one();
         $es2 = new entity_selector();
         $es2->add_type(id_of('content_table'));
         $es2->add_relation('entity.name = "event"');
         $es2->set_num(1);
         $event_result = $es2->run_one();
         if ($location_result && $event_result) {
             $location_table = reset($location_result);
             $event_result = reset($event_result);
             $field_to_entity_table_id = relationship_id_of('field_to_entity_table');
             $es3 = new entity_selector();
             $es3->add_type(id_of('field'));
             $es3->add_relation('entity.name = "location"');
             $es3->add_left_relationship($location_table->id(), $field_to_entity_table_id);
             $es3->set_num(1);
             $es3_result = $es3->run_one();
             if ($es3_result) {
                 $field = reset($es3_result);
                 // create the column on the event table
                 $q = "ALTER TABLE event ADD location " . $field->get_value('db_type');
                 $r = db_query($q, 'Problems - could not add the location column to the event table');
                 $sqler = new SQLER();
                 // populate the values for the new column
                 if (isset($ids)) {
                     foreach ($ids as $id => $location) {
                         $sqler->update_one('event', array('location' => $location), $id);
                     }
                 }
                 // update the entity table for the field_to_entity_table_relationship at hand
                 $q = 'UPDATE relationship SET entity_b=' . $event_result->id();
                 $q .= ' WHERE entity_a=' . $field->id() . ' AND entity_b=' . $location_table->id() . ' AND type=' . $field_to_entity_table_id;
                 db_query($q);
                 // create the column on the event table
                 $q = "DROP TABLE location";
                 $r = db_query($q, 'Could not drop the entity table location');
                 reason_expunge_entity($location_table->id(), $this->reason_id);
                 echo '<p>Moved location.location to event.location, and deleted the location entity table</p>';
             }
         }
     } elseif ($this->mode == 'test') {
         echo '<p>Would move the location.location to event.location, and delete the location entity table</p>';
     }
 }