Esempio n. 1
0
 /**
  * Standard Module init function
  *
  * @return void
  */
 function init()
 {
     parent::init();
     if (!reason_user_has_privs($this->admin_page->user_id, 'delete')) {
         $this->_ok_to_run = false;
         $this->_not_ok_message = 'Sorry; you don\'t have the privileges to delete items on this site.';
     } elseif (empty($this->admin_page->site_id)) {
         $this->_ok_to_run = false;
         $this->_not_ok_message = 'Sorry; you need to specify a site before batch deleting items.';
     } elseif (empty($this->admin_page->type_id)) {
         $this->_ok_to_run = false;
         $this->_not_ok_message = 'Sorry; you need to specify a type before batch deleting items.';
     }
     if ($this->_ok_to_run) {
         $this->_type = new entity($this->admin_page->type_id);
         $this->admin_page->title = 'Batch Delete ' . $this->_type->get_value('plural_name');
         $es = new entity_selector($this->admin_page->site_id);
         $es->add_type($this->admin_page->type_id);
         $es->set_sharing('owns');
         $es->set_order('entity.last_modified DESC');
         // pray($this->admin_page->request);
         if (isset($this->admin_page->request['state']) && $this->admin_page->request['state'] == 'pending') {
             $status = 'Pending';
         } else {
             $status = 'Live';
         }
         $this->_items = $es->run_one('', $status);
         foreach (array_keys($this->_items) as $id) {
             if (!$this->admin_page->is_deletable($id)) {
                 unset($this->_items[$id]);
             }
         }
     }
 }
 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;
     }
 }
 /**
  * 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_events()
		{
			if(!isset($this->events))
			{
				$es = new entity_selector($this->site_id);
				$es->add_type(id_of('event_type'));
				
				if(!in_array('archived',$this->params['show']))
				{
					$es->add_relation('`last_occurence` >= "'.addslashes(date('Y-m-d')).'"');
				}
				if(!in_array('upcoming',$this->params['show']))
				{
					$es->add_relation('`datetime` < "'.addslashes(date('Y-m-d',time() + (60*60*24))).'"');
				}
				if(!in_array('current',$this->params['show']))
				{
					$es->add_relation('(`last_occurence` < "'.addslashes(date('Y-m-d')).'" OR `datetime` >= "'.addslashes(date('Y-m-d',time() + (60*60*24))).'")');
				}
				$es->add_relation('`show_hide` = "show"');
				$es->set_order($this->params['order']);
				$this->_modify_events_es($es);
				$events = $es->run_one();
				$class = $this->get_model_class($this->params['model']);
				foreach($events as $id => $event)
				{
					$this->events[$id] = new $class($event);
				}
				if(empty($this->events))
					$this->events = array();
			}
			return $this->events;
		}
Esempio n. 5
0
 function get_entity_selector()
 {
     $es = new entity_selector($this->admin_page->site_id);
     $es->add_type($this->admin_page->type_id);
     $es->set_order($this->get_table() . '.' . $this->get_field() . ' ASC');
     $es->set_sharing('owns');
     $es = $this->update_es($es);
     return $es;
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
 function init($args = array())
 {
     parent::init($args);
     $s = new entity_selector();
     $s->add_type(id_of('site'));
     $s->set_order('entity.name');
     $s->add_relation('site.site_state = "Live"');
     $this->site_count = $s->get_one_count();
     $this->sites = $s->run_one();
     //pray($this->sites);
 }
Esempio n. 10
0
 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 alter_values()
 {
     $parent = new entity_selector();
     $parent->add_field('entity2', 'id', 'parent_id');
     $parent->add_table('allowable_relationship2', 'allowable_relationship');
     $parent->add_table('relationship2', 'relationship');
     $parent->add_table('entity2', 'entity');
     $parent->add_relation('entity2.id =  relationship2.entity_b');
     $parent->add_relation('entity.id = relationship2.entity_a');
     $parent->add_relation('relationship2.type = allowable_relationship2.id');
     $parent->add_relation('allowable_relationship2.name LIKE "%parent%"');
     $parent->set_order('sortable.sort_order');
     $this->es->swallow($parent);
     $this->remove_column('id');
 }
Esempio n. 12
0
 function get_description($site)
 {
     $es = new entity_selector($site->id());
     $es->add_type(id_of('text_blurb'));
     $es->add_relation('entity.name = "Site Description"');
     $es->set_order('entity.last_modified DESC');
     $descriptions = $es->run_one();
     if (!empty($descriptions)) {
         reset($descriptions);
         $desc = current($descriptions);
         return $desc->get_value('content');
     } elseif ($site->get_value('description')) {
         return $site->get_value('description');
     } else {
         return NULL;
     }
 }
Esempio n. 13
0
 /**
  * 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;
 }
Esempio n. 14
0
 public function get_image()
 {
     if (!isset($this->_image)) {
         $es = new entity_selector();
         $es->add_type(id_of('image'));
         $es->add_right_relationship($this->_event->id(), relationship_id_of('event_to_image'));
         $es->add_rel_sort_field($this->_event->id(), relationship_id_of('event_to_image'));
         $es->set_order('rel_sort_order ASC');
         $es->set_num(1);
         $images = $es->run_one();
         if (!empty($images)) {
             $this->_image = current($images);
         } else {
             $this->_image = false;
         }
     }
     return $this->_image;
 }
Esempio n. 15
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. 16
0
 /**
  * Standard Module init function
  *
  * Sets up the entity selectors and grabs the site lists
  * 
  * @return void
  */
 function init()
 {
     parent::init();
     $this->site = new entity($this->admin_page->site_id);
     $this->admin_page->title = 'Site Listing';
     $lm = new entity_selector();
     $lm->add_type(id_of('site'));
     $lm->set_order('entity.name');
     $lm->add_relation('site.site_state = "Live"');
     $this->ls_count = $lm->get_one_count();
     $this->live_sites_list = $lm->run_one();
     if (reason_user_has_privs($this->admin_page->user_id, 'view_sensitive_data')) {
         $nm = new entity_selector();
         $nm->add_type(id_of('site'));
         $nm->set_order('entity.name');
         $nm->add_relation('site.site_state != "Live"');
         $this->nls_count = $nm->get_one_count();
         $this->not_live_site_list = $nm->run_one();
     }
 }
Esempio n. 17
0
 function init()
 {
     $this->head_items->add_stylesheet(REASON_ADMIN_CSS_DIRECTORY . 'archive.css');
     $this->current = new entity($this->admin_page->id);
     $this->_current_user = new entity($this->admin_page->user_id);
     $this->admin_page->title = 'History of "' . $this->current->get_value('name') . '"';
     $this->ignore_fields = array('id', 'last_edited_by', 'last_modified', 'creation_date', 'type', 'created_by', 'new', 'state');
     // get archive relationship id
     $this->rel_id = reason_get_archive_relationship_id($this->admin_page->type_id);
     $es = new entity_selector();
     $es->add_type($this->admin_page->type_id);
     $es->add_right_relationship($this->admin_page->id, $this->rel_id);
     $es->set_order('last_modified DESC, entity.id DESC');
     $archived = $es->run_one(false, 'Archived');
     $this->_locks[$this->current->id()] = array();
     // No problem replacing current entity with itself!
     foreach ($archived as $archive_id => $archive_entity) {
         $this->_locks[$archive_id] = $this->_get_archive_lock_info($archive_entity);
     }
     $history_top = array($this->current->id() => $this->current);
     $this->history = $history_top + $archived;
 }
Esempio n. 18
0
 function grab_sites($name, $site_type_id_array)
 {
     $sites_by_type = array();
     $sites_by_type[$this->id_of_site_type] = array();
     $sites_by_type[$this->id_of_non_reason_site_type] = array();
     foreach ($site_type_id_array as $site_type_id) {
         $r_es = new entity_selector();
         $r_es->description = 'Getting all ' . $name;
         $r_es->add_type($this->id_of_site_type);
         $r_es->add_relation('site.site_state = "Live"');
         $r_es->add_left_relationship($site_type_id, relationship_id_of('site_to_site_type'));
         $r_es->set_order('entity.name ASC');
         $sites_by_type[$this->id_of_site_type] += $r_es->run_one();
         $nr_es = new entity_selector();
         $nr_es->description = 'Getting all ' . $name;
         $nr_es->add_type($this->id_of_non_reason_site_type);
         $nr_es->add_left_relationship($site_type_id, relationship_id_of('non_reason_site_to_site_type'));
         $nr_es->add_relation('site.site_state = "Live"');
         $sites_by_type[$this->id_of_non_reason_site_type] += $nr_es->run_one();
     }
     $this->list_sites($sites_by_type, $name);
 }
 function show_site($site)
 {
     $link = $site->get_value('base_url');
     echo '<li>' . "\n";
     echo '<h4><a href="' . $link . '">' . $site->get_value('name') . '</a></h4>' . "\n";
     $es = new entity_selector($site->id());
     $es->description = 'Getting pages for child site';
     $es->add_type(id_of('minisite_page'));
     $es->add_left_relationship_field('minisite_page_parent', 'entity', 'id', 'parent_id');
     $es->add_relation('page_node.nav_display = "Yes"');
     $es->set_order('sortable.sort_order');
     $pages = $es->run_one();
     $parents = array();
     foreach ($pages as $page) {
         if ($page->id() == $page->get_value('parent_id')) {
             $root_page_id = $page->id();
         } else {
             $parents[$page->get_value('parent_id')][$page->id()] = $page;
         }
     }
     $this->display_pages($link, $parents, $root_page_id);
     echo '</li>' . "\n";
 }
Esempio n. 20
0
 /**
  * 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;
         }
     }
 }
 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();
 }
Esempio n. 22
0
 /**
  * Get sites - exclude master_admin
  */
 function get_json()
 {
     $site_id = $this->config('site_id');
     $site = new entity($site_id);
     $restrict_to_live = $site->get_value('site_state') == 'Live';
     $es = new entity_selector();
     $es->add_type(id_of('site'));
     $es->limit_tables('site');
     $es->limit_fields('id', 'name');
     $es->add_relation('( (custom_url_handler = "") OR (custom_url_handler IS NULL) )');
     $es->set_order('name ASC');
     if ($restrict_to_live) {
         $es->add_relation('site_state = "Live"');
     }
     if ($results = $es->run_one()) {
         $sites['count'] = 0;
         foreach ($results as $result) {
             $sites['sites'][] = array('name' => strip_tags($result->get_value('name')), 'id' => $result->id());
             $sites['count']++;
         }
         return json_encode($sites);
     } else {
         return json_encode(array('count' => 0, 'sites' => array()));
     }
 }
 /**
  * Generates and returns the html markup used to represent an audio media work.
  *
  * @access private
  * @return string embed markup
  */
 private function _get_audio_embed_markup()
 {
     $markup = '<audio id="' . $this->media_work->id() . '" preload="metadata" ';
     if ($this->show_controls) {
         $markup .= 'controls="controls" ';
     }
     if ($this->autostart) {
         $markup .= 'autoplay="autoplay" ';
     }
     $markup .= '>';
     $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'));
     $es->set_order('av.mime_type ASC');
     // 'mpeg' comes before 'ogg'
     $this->media_files = $es->run_one();
     $mp3 = false;
     foreach ($this->media_files as $file) {
         $markup .= '<source src="' . $this->_match_protocol($file->get_value('url')) . '" type="' . $file->get_value('mime_type') . '" />' . "\n";
         if ($file->get_value('mime_type') == 'audio/mpeg') {
             $mp3 = $file;
         }
     }
     // Fall back to flash player
     if ($mp3) {
         $avd = new reasonAVDisplay();
         $avd_autoplay = $this->autostart ? 'true' : 'false';
         $avd->set_parameter('flv', 'autostart', $avd_autoplay);
         if (!$this->show_controls) {
             $avd->set_parameter('flv', 'controlbar', '0');
         }
         $mp3->set_value('url', $this->_match_protocol($mp3->get_value('url')));
         $avd_markup = $avd->get_embedding_markup_For_flash_video($mp3);
         $markup .= $avd_markup;
         // return $avd_markup;  // uncomment this if testing the flash player
     }
     $markup .= '</audio>' . "\n";
     return $markup;
 }
Esempio n. 24
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. 25
0
 /**
  * Grab the site page entities respect the table_sort_order field if table_sort_field is equal to last_modified
  */
 function _get_site_pages()
 {
     if (!isset($this->_site_pages)) {
         if ($site_id = $this->_get_validated_site_id()) {
             $sort_order_string = $this->_get_sort_order_string();
             $es = new entity_selector($site_id);
             $es->add_type(id_of('minisite_page'));
             $es->add_relation('(entity.name != "") AND ((url.url = "") OR (url.url IS NULL))');
             // only pages, not custom urls
             $es->set_order('last_modified ' . $sort_order_string);
             $this->_site_pages = $es->run_one();
             if ($this->_site_pages) {
                 $this->_augment_page_entities($this->_site_pages);
             }
         } else {
             $this->_site_pages = false;
         }
     }
     return $this->_site_pages;
 }
Esempio n. 26
0
		function get_filter_entities()
		{
			if(is_null($this->filter_entities))
			{
				$this->filter_entities = array();
				foreach($this->filter_types as $filter_name=>$filter_type)
				{
					$r_id = false;
					if(empty($filter_type['relationship'])) trigger_error($filter_type['type'].' does not have a relationship name specified');
					else
					{
						$r_id = relationship_id_of($filter_type['relationship']);
						if (!$r_id) trigger_error($filter_type['relationship'] . ' is not a valid allowable relationship');
					}
					$es = new entity_selector($this->parent->site_id);
					$es->add_type(id_of($filter_type['type']));
					$es->set_order('entity.name ASC');
					$filter_entities = $es->run_one();
					
					if(!empty($filter_entities))
					{
						// check to make sure the relationship filtering makes sense for each item
						if($this->params['limit_to_current_site'])
						{
							$setup_es = new entity_selector($this->parent->site_id);
						}
						else
						{
							$setup_es = new entity_selector();
						}
						$setup_es->add_type( $this->type );
						$setup_es->set_env('site_id',$this->parent->site_id);
						$setup_es = $this->alter_relationship_checker_es($setup_es);
						$setup_es->set_num(1);
						foreach($filter_entities as $key=>$filter)
						{
							$es = carl_clone($setup_es);
							$es->add_left_relationship( $filter->id(), $r_id );
							$results = $es->run_one();
							if(empty($results))
							{
								unset($filter_entities[$key]);
							}
							$results = array();
						}
						if(!empty($filter_entities))
						{
							$this->filter_entities[$filter_name] = $filter_entities;
						}
					}
				}
				ksort($this->filter_entities);
			}
			
			return $this->filter_entities;
			
		}
Esempio n. 27
0
 function _get_max_sort_order_value($page_id)
 {
     $es = new entity_selector();
     $es->add_type(id_of('image'));
     $es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image'));
     $es->add_field('relationship', 'id', 'rel_id');
     $es->add_rel_sort_field($page_id);
     $es->set_order('relationship.rel_sort_order DESC');
     $es->set_num(1);
     $images = $es->run_one();
     if (!empty($images)) {
         $image = current($images);
         if ($image->get_value('rel_sort_order')) {
             return $image->get_value('rel_sort_order');
         }
     }
     return 0;
 }
 /**
  * Identify the images that should be displayed
  */
 function select_images()
 {
     // Initialize the images with appropriate entity selector properties
     $page_id = $this->page_id;
     if (!empty($this->params['alternate_source_page_id'])) {
         $page_id = $this->params['alternate_source_page_id'];
         if (!($site_id = get_owner_site_id($page_id))) {
             $site_id = $this->site_id;
         }
     } else {
         $page_id = $this->cur_page->id();
         $site_id = $this->site_id;
     }
     $es = new entity_selector();
     $es->add_type(id_of('image'));
     $es->set_env('site', $site_id);
     $es->add_right_relationship($page_id, relationship_id_of('minisite_page_to_image'));
     if ($this->params['rand_flag']) {
         $es->set_order('rand()');
     } elseif (!empty($this->params['order_by'])) {
         $es->set_order($this->params['order_by']);
     } else {
         $es->add_rel_sort_field($page_id, relationship_id_of('minisite_page_to_image'));
         $es->set_order('rel_sort_order');
     }
     if (!empty($this->params['num_to_display'])) {
         $es->set_num($this->params['num_to_display']);
     }
     $this->images = $es->run_one();
 }
Esempio n. 29
0
 function run()
 {
     if (!reason_user_has_privs($this->admin_page->user_id, 'view_sensitive_data')) {
         echo '<p>Sorry; use of this module is restricted.</p>' . "\n";
         return;
     }
     if (!empty($this->admin_page->request['export_site_id'])) {
         $site_id = $this->admin_page->request['export_site_id'];
         settype($site_id, 'integer');
     }
     if (empty($site_id)) {
         $site_id = '';
     }
     if (!empty($this->admin_page->request['export_type_id'])) {
         $type_id = $this->admin_page->request['export_type_id'];
         settype($type_id, 'integer');
     }
     if (empty($type_id)) {
         $type_id = '';
     }
     $es = new entity_selector();
     $es->set_order('entity.name ASC');
     $sites = $es->run_one(id_of('site'));
     $types = $es->run_one(id_of('type'));
     echo '<form method="get" action="?">';
     echo '<label for="export_site_id">Site:</label>';
     echo '<select name="export_site_id" id="export_site_id">';
     foreach ($sites as $site) {
         echo '<option value="' . $site->id() . '"';
         if ($site->id() == $site_id) {
             echo ' selected="selected"';
         }
         echo '>' . $site->get_value('name') . '</option>' . "\n";
     }
     echo '</select><br />' . "\n";
     echo '<label for="export_type_id">Type:</label>';
     echo '<select name="export_type_id" id="export_type_id">';
     echo '<option value="">All</option>' . "\n";
     foreach ($types as $type) {
         echo '<option value="' . $type->id() . '"';
         if ($type->id() == $type_id) {
             echo ' selected="selected"';
         }
         echo '>' . $type->get_value('name') . '</option>' . "\n";
     }
     echo '</select><br />' . "\n";
     echo '<input type="submit" value="submit" /><input type="hidden" name="cur_module" value="Export" />';
     echo '</form>' . "\n";
     if (!empty($site_id)) {
         if (!empty($type_id) && isset($types[$type_id])) {
             $query_types = array($type_id => $types[$type_id]);
         } else {
             $query_types = $types;
         }
         $es = new entity_selector($site_id);
         $entities = array();
         foreach ($query_types as $type) {
             $entities = array_merge($entities, $es->run_one($type->id()));
         }
         $export = new reason_xml_export();
         echo '<textarea rows="40">' . htmlspecialchars($export->get_xml($entities), ENT_QUOTES) . '</textarea>' . "\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');
}
$d = new DiscoMoveEntities();