function alter_values() { $this->setup_associated_items(); // show items the site owns or borrows - add sharing field $this->es->set_sharing('owns,borrows'); if (reason_relationship_names_are_unique()) { $this->es->add_table('ar', 'allowable_relationship'); $this->es->add_field('ar', 'type', 'sharing'); $this->es->add_relation('r.type = ar.id'); } else { $this->es->add_field('ar', 'name', 'sharing'); } // modify entity selector to exclude items that are already associated if ($this->ass_vals) { $relation = 'entity.id NOT IN (' . implode(",", array_keys($this->ass_vals)) . ')'; $this->es->add_relation($relation); } // modify entity selector to exlude items that should not be available for association because they are already part of a many_to_one relationship // currently this will only run for unidirectional relationships since bidirectional rels are forced to be many_to_many if ($this->admin_page->module->associations[$this->admin_page->rel_id]['connections'] == 'many_to_one') { $ass_related_es = carl_clone($this->es); $ass_related_es->add_right_relationship_field(relationship_name_of($this->admin_page->rel_id), 'entity', 'id', 'related_id'); $this->related_vals = $ass_related_es->run_one(); if ($this->related_vals) { $relation = 'entity.id NOT IN (' . implode(",", array_keys($this->related_vals)) . ')'; $this->es->add_relation($relation); } } }
function alter_values() { $this->add_column('site'); $this->update_es(); $ass_es = new entity_selector($this->admin_page->site_id); $ass_es->add_type($this->admin_page->type_id); $ass_es->set_sharing('borrows'); $ass_es->limit_fields(); //grab site name as well $this->alias = $ass_es->add_right_relationship_field('owns', 'entity', 'name', 'site'); $ass_es->add_right_relationship_field('owns', 'entity', 'id', 'site_id'); if ($this->site_is_live()) { $ass_es->add_right_relationship_field('owns', 'entity', 'state', 'site_state', 'Live'); } $this->apply_order_and_limits($ass_es); $this->ass_vals = $ass_es->run_one(); if ($this->ass_vals) { $this->es->add_relation('entity.id NOT IN ("' . implode('","', array_keys($this->ass_vals)) . '")'); } if (!empty($this->admin_page->request['__old_rel_id'])) { $conn_name = $this->get_connection($this->admin_page->request['__old_rel_id']); if ($conn_name == 'many_to_one') { $ass_related_es = carl_clone($this->es); $ass_related_es->add_right_relationship_field(relationship_name_of($this->admin_page->request['__old_rel_id']), 'entity', 'id', 'related_id'); $this->related_vals = $ass_related_es->run_one(); if ($this->related_vals) { $this->es->add_relation('entity.id NOT IN ("' . implode('","', array_keys($this->related_vals)) . '")'); } } } }
function init($args = array()) { if ($this->params['limit_by_page_categories']) { trigger_error('limit_by_page_categories is a deprecated parameter. Use organize_by_page_categories instead.'); $this->params['organize_by_page_categories'] = $this->params['limit_by_page_categories']; $this->params['limit_by_page_categories'] = false; } $this->site = new entity($this->site_id); $this->es = new entity_selector(); $this->es->description = 'Selecting assets for this page'; $this->es->set_env('site', $this->site_id); $this->es->add_type(id_of('asset')); $this->es->add_right_relationship($this->page_id, relationship_id_of('page_to_asset')); if (!empty($this->params['order'])) { $this->es->set_order($this->params['order']); } else { $this->es->add_rel_sort_field($this->page_id, relationship_id_of('page_to_asset')); $this->es->set_order('rel_sort_order'); } if ($this->params['organize_by_page_categories']) { $es_by_cat = carl_clone($this->es); } $this->assets = $this->es->run_one(); if ($this->assets) { if ($this->params['organize_by_page_categories']) { $es_by_cat->enable_multivalue_results(); $es_by_cat->add_left_relationship_field('asset_to_category', 'entity', 'id', 'cat_id'); // grab category ids $result = $es_by_cat->run_one(); if (!empty($result)) { $this->assets_by_category =& $this->init_by_category($result); } } } if ($this->params['offer_merged_pdfs'] && !empty($this->request['asset_view']) && $this->request['asset_view'] == 'merged_pdf') { $this->_merge_and_send_pdfs($this->_get_pdfs_to_merge()); } }
function init_from_database() { $init_array = array_merge($this->init_array, array('ideal_count' => $this->optimal_event_count * 3, 'start_date' => $this->startdate)); if (count($this->audience_limit)) { $aud_array = array(); foreach ($this->audience_limit as $audience) { $aud_id = id_of($audience); if ($aud_id) { $aud_array[] = new entity($aud_id); } } if (count($aud_array)) { $init_array['audiences'] = $aud_array; } } if (count($this->category_limit)) { $cat_array = array(); foreach ($this->category_limit as $category) { $cat_id = id_of($category); if ($cat_id) { $cat_array[] = new entity($cat_id); } } if (count($cat_array)) { if ($this->or_categories) { $init_array['or_categories'] = $cat_array; } else { $init_array['categories'] = $cat_array; } } } $this->calendar = new reasonCalendar($init_array); $this->calendar->run(); $full_event_pool = $this->calendar->get_all_events(); //$event_days = $this->calendar->get_all_days(); $event_pool = array(); $events = array(); $event_count = 0; // relative definition of now allows testing of different days $now = strtotime($this->startdate . ' ' . $this->starttime); // For repeating events, we need to split the repeats up into the right dates foreach ($this->calendar->events_by_date as $date => $day) { foreach ($day as $event) { if ($full_event_pool[$event]->get_value('dates') != $full_event_pool[$event]->get_value('last_occurence')) { foreach (explode(',', $full_event_pool[$event]->get_value('dates')) as $occurence) { if ($occurence != $date && $occurence >= $this->startdate) { $this->calendar->events_by_date[$occurence][] = $event; } } } } } ksort($this->calendar->events_by_date); foreach ($this->calendar->events_by_date as $date => $day) { // for some reason, the calendar class returns duplicates in a single day, so we need to unique them away $sorted_events = array_unique($this->calendar->sort_event_ids_by_time_of_day($day)); foreach ($sorted_events as $event) { // we need to copy the event object here in case it's a recurring event $event_pool[$date][$event] = carl_clone($full_event_pool[$event]); $event_pool[$date][$event]->set_value('date', $date); $event_pool[$date][$event]->set_value('display_date', date('l, F jS', strtotime($date))); list($d, $t) = explode(' ', $event_pool[$date][$event]->get_value('datetime')); $event_pool[$date][$event]->set_value('time', $t); $event_pool[$date][$event]->set_value('display_time', date('g:ia', strtotime($event_pool[$date][$event]->_values['datetime']))); $this->set_range_timestamps($event_pool[$date][$event]); $this->set_page_link($event_pool[$date][$event]); // If this event is still going on or is in the future... if ($event_pool[$date][$event]->get_value('end_stamp') > $now) { // If we have enough events, and this event starts more than the lookahead span from now, we're done if ($event_count >= $this->optimal_event_count && $event_pool[$date][$event]->get_value('start_stamp') > $now + $this->lookahead_minutes * 60 + 60) { break 2; } else { $events[$date][$event] = $event_pool[$date][$event]; $event_count++; } } } } $this->events = $events; $this->set_cache(); }
function add_relationship_element($name, $type_id, $rel_id, $direction = 'right', $element_type = 'checkbox', $limit_to_site = true, $sort = 'entity.name ASC') { static $directions = array('right', 'left'); static $element_types = array('checkbox' => array('plasmature_type' => 'checkboxgroup_no_sort'), 'radio' => array('plasmature_type' => 'radio_no_sort'), 'select' => array('plasmature_type' => 'select_no_sort', 'args' => array('add_empty_value_to_top' => true)), 'multiple_select' => array('plasmature_type' => 'select_no_sort', 'args' => array('size' => 7, 'multiple' => true), 'comment' => 'Control-click (PC) or Command-click (Mac) to choose multiple items')); static $single_item_element_types = array('radio', 'select'); if (!array_key_exists($element_type, $element_types)) { trigger_error($element_type . ' is not an acceptable parameter for add_relationship_element(). Try one of the following: ' . implode(', ', $element_types)); return; } if (!in_array($direction, $directions)) { trigger_error($direction . ' is not an acceptable parameter for add_relationship_element(). Try one of the following: ' . implode(', ', $directions)); return; } $rel_info = $this->get_relationship_info($rel_id); if ($direction == 'right' && $rel_info['connections'] == 'one_to_many' || $direction == 'left' && $rel_info['connections'] == 'many_to_one') { $can_relate_multiple_items = false; } else { $can_relate_multiple_items = true; } if (!empty($rel_info)) { if (!in_array($element_type, $single_item_element_types)) { if (!$can_relate_multiple_items) { trigger_error('Rel type mismatch -- only these element types can be used with a one_to_many relationship: ' . implode(', ', $single_item_element_types)); return; } } } else { trigger_error($rel_id . ' does not appear to be an allowable relationship ID'); return; } if ($limit_to_site) { $es = new entity_selector($this->get_value('site_id')); } else { $es = new entity_selector(); } $es->add_type($type_id); if ($this->get_value('site_id')) { $es->set_env('site', $this->get_value('site_id')); } $rel_es = carl_clone($es); if ($direction == 'right') { $rel_es->add_right_relationship($this->get_value('id'), $rel_id); } else { $rel_es->add_left_relationship($this->get_value('id'), $rel_id); $rel_es->add_right_relationship_field('owns', 'entity', 'id', 'owner_id'); } if (in_array($element_type, $single_item_element_types)) { $rel_es->set_num(1); } //$rel_es->add_field('relationship','id','rel_id'); $rel_es->set_order($sort); $rel_es->add_field('relationship', 'site', 'rel_site_id'); $related_entities = $rel_es->run_one(); $related_keys = array(); $untouchables = array(); foreach ($related_entities as $entity) { if ($direction == 'right' || $entity->get_value('owner_id') == $this->get_value('site_id') || $entity->get_value('rel_site_id') == $this->get_value('site_id')) { $related_keys[] = $entity->id(); } else { $untouchables[$entity->id()] = strip_tags($entity->get_display_name()); } } if (!empty($untouchables)) { $es->add_relation('entity.id NOT IN (' . implode(',', array_keys($untouchables)) . ')'); } $es->set_order($sort); $entities = $es->run_one(); $values = array(); foreach ($entities as $entity) { $values[$entity->id()] = strip_tags($entity->get_display_name()); } $args = array(); if (!empty($element_types[$element_type]['args'])) { $args = $element_types[$element_type]['args']; } $args['options'] = $values; $this->add_element($name, $element_types[$element_type]['plasmature_type'], $args); if (!empty($related_keys)) { if (in_array($element_type, $single_item_element_types)) { $this->set_value($name, current($related_keys)); } else { $this->set_value($name, $related_keys); } } if ($direction == 'right' && $rel_info['required'] == 'yes') { if (!empty($entities)) { $this->add_required($name); } else { $this->add_comments($name, '<em>None available</em>'); } } if (!empty($untouchables)) { $this->add_comments($name, '<div class="otherSiteRelation"><strong>Attached to this item by another site:</strong><ul class="smallText"><li>' . implode('</li><li>', $untouchables) . '</li></ul></div>', 'before'); } if (!empty($element_types[$element_type]['comment'])) { $this->add_comments($name, form_comment($element_types[$element_type]['comment'])); } $this->_relationship_elements[$name] = array('type_id' => $type_id, 'rel_id' => $rel_id, 'direction' => $direction, 'options' => array_keys($entities), 'related_at_prep' => $related_keys); if (!in_array($name, $this->_no_tidy)) { $this->_no_tidy[] = $name; } }
/** * Returns entity selector with featured items for the current publication - stored in a static variable * so that the entity selector will not be run multiple times by different modules or the same publication */ function get_featured_items() { if ($this->related_mode) return $this->get_related_featured_items(); else { $page_num = isset($this->request['page']) ? $this->request['page'] : 1; if ($this->show_featured_items == false || $page_num > 1) return array(); static $featured_items; if (!isset($featured_items[$this->publication->id()])) { $es = (isset($this->pre_pagination_es)) ? carl_clone($this->pre_pagination_es) : carl_clone($this->es); $es->description = 'Selecting featured news items for this publication'; $es->add_right_relationship( $this->publication->id(), relationship_id_of('publication_to_featured_post') ); $es->add_rel_sort_field($this->publication->id(), relationship_id_of('publication_to_featured_post'), 'featured_sort_order' ); $es->set_order('featured_sort_order ASC'); $es->set_num(-1); $featured_items[$this->publication->id()] = $es->run_one(); } return $featured_items[$this->publication->id()]; } }
/** * pray - short for print_array * * Traverse the argument array/object recursively and print an ordered list. * Optionally show function names (in an object) * * NB: This is a *** HUGE SECURITY HOLE *** in the wrong hands!! * It prints all the variables it can find * If the argument is $GLOBALS this will include your database connection * information, magic keys and session data!! * * This function should only be used when debugging or trying to understand the * structure of some array-like data. It should not show up in production code. * * Changelog: * * sometime earlier * * added $escape param. will htmlentities() all values if set to true instead of displaying HTML * 13 Dec 02 * * modified to show actual "empty" value. If something doesn't have a value, it will display 0, NULL, false, or (none) depending on type. * added strict check for true. shows 'true' if var is true and of type bool * * 28 Jan 03 * * infinite recursion is bad. added level and max_depth vars * * @param mixed $data Whatever you want to inspect * @param boolean $escape true = htmlentities() all strings; false = output raw * @param boolean $functions Unclear purpose * @param integer $level How deep has pray() recursed so far? * @param integer $max_depth How deep should pray() recurse? * * @todo figure out what the $functions parameter is all about */ function pray($data, $escape = false, $functions = false, $level = 0, $max_depth = 5) { if (is_object($data)) { $data = carl_clone($data); } if ($level >= $max_depth) { echo 'Max Depth reached.'; } else { if ($functions != 0) { $sf = 1; } else { $sf = 0; } // This kluge seemed necessary on one server. if (isset($data)) { if (is_array($data) || is_object($data)) { if (count($data)) { echo '<ul>' . "\n"; while (list($key, $value) = each($data)) { echo '<li>'; $type = gettype($value); if ($type == "array" || $type == "object") { if ($type == 'object') { $type = $type . ' - ' . get_class($value); } if ($escape) { $type = htmlentities($type); $type = get_class($value); $key = htmlentities($key); } printf("(%s)<strong>%s</strong>:\n", $type, $key); pray($value, $escape, $sf, $level + 1); } elseif (preg_match("/function/i", $type)) { if ($sf) { if ($escape) { $type = htmlentities($type); $key = htmlentities($key); $value = htmlentities($value); } printf("(%s) <strong>%s</strong>", $type, $key, $value); // There doesn't seem to be anything traversable inside functions. } } else { if (!$value) { // show actual non-value switch (gettype($value)) { case 'integer': case 'double': $value = '0'; break; case 'boolean': $value = 'false'; break; case 'NULL': $value = 'NULL'; break; default: $value = "(none)"; break; } } // check for strict equivalance to true if ($value === true) { $value = 'true'; } if ($escape) { $type = htmlentities($type); $key = htmlentities($key); $value = nl2br(htmlentities($value)); } printf("(%s) <strong>%s</strong> = %s", $type, $key, $value); } echo '</li>' . "\n"; } echo "</ul>\n"; } else { echo '(empty)' . "\n"; } } } } }
/** * Check bounds of page, make sure it's in range * Sets up appropriate variables if not already set * @return void */ function &check_bounds(&$es) { $clone_es = carl_clone($es); $clone_es->optimize('distinct'); $clone_es->limit_fields(); // we limit fields since mostly we want a count and will perform another select in load_values; $ids = $clone_es->get_ids($this->type_id, $this->state); $this->real_count = count($ids); if( empty( $this->page ) ) $this->page = 1; $max_page = ceil( $this->real_count / $this->num_per_page ); if( $this->page > $max_page ) $this->page = $max_page; if( $this->page < 1 ) $this->page = 1; return $ids; }
/** * Initialiation function for event detail mode * * @todo should probably just grab audience and categories right here. * * @return void */ function init_event() // {{{ { $this->event = new entity($this->request['event_id']); if ($this->event_ok_to_show($this->event)) { if(!empty($this->request['format']) && $this->request['format'] == 'ical') { $event = carl_clone($this->event); if(!empty($this->request['date'])) { $event->set_value('recurrence','none'); $event->set_value('datetime',$this->request['date'].' '.prettify_mysql_datetime($event->get_value('datetime'), 'H:i:s')); } $this->export_ical(array($event)); } else { $this->_add_crumb( $this->event->get_value( 'name' ) ); $this->parent->pages->make_current_page_a_link(); if($head_items = $this->get_head_items() ) { if($this->event->get_value('keywords')) { $head_items->add_head_item('meta',array( 'name' => 'keywords', 'content' => htmlspecialchars($this->event->get_value('keywords'),ENT_QUOTES,'UTF-8'))); } } $this->verify_and_set_up_registration_slots(); } } } // }}}
function run() { echo '<div id="siteIntro">' . "\n"; $e = new entity($this->admin_page->site_id); echo '<div id="siteNotices">' . "\n"; if ($e->get_value('site_state') == "Not Live" && $e->get_value('unique_name') != 'master_admin') { echo '<div class="notLiveNotice"><h4>This site is not live.</h4><p>Among other things, that means that it\'s excluded from search engines (so people won\'t stumble upon a site that isn\'t ready for public consumption).</p>' . "\n"; if (user_can_edit_site($this->admin_page->user_id, id_of('master_admin'))) { echo '<p><a href="' . $this->admin_page->make_link(array('site_id' => id_of('master_admin'), 'type_id' => id_of('site'), 'id' => $e->id(), 'cur_module' => 'Editor')) . '">Edit this site</a></p>' . "\n"; } else { echo '<p>Please contact ' . REASON_CONTACT_INFO_FOR_CHANGING_USER_PERMISSIONS . ' when you are ready to make this site live.</p>' . "\n"; } echo '</div>' . "\n"; } if ($e->get_value('description')) { echo '<div id="siteDesc">' . "\n"; if (strip_tags($e->get_value('description')) == $e->get_value('description')) { echo nl2br($e->get_value('description')); } else { echo $e->get_value('description'); } echo '</div>' . "\n"; } $sites = $this->admin_page->get_sites(); if (count($sites) == 1) { parent::run(); } echo '</div>' . "\n"; echo '<div id="guide">' . "\n"; $es = new entity_selector(); $es->add_type(id_of('type')); $es->add_right_relationship($e->id(), relationship_id_of('site_to_type')); $es->limit_tables(); $es->limit_fields(); $non_editable_es = carl_clone($es); $non_editable_es->add_right_relationship($e->id(), relationship_id_of('site_cannot_edit_type')); $noneditable_types = $non_editable_es->run_one(); if (!empty($noneditable_types)) { $es->add_relation('entity.id NOT IN (' . implode(',', array_keys($noneditable_types)) . ')'); } $es->set_order('entity.name ASC'); $types = $es->run_one(); if (array_key_exists(id_of('minisite_page'), $types)) { $page_type_array[id_of('minisite_page')] = $types[id_of('minisite_page')]; unset($types[id_of('minisite_page')]); $types = array_merge($page_type_array, $types); } echo '<ul>' . "\n"; foreach ($types as $type) { $es = new entity_selector($e->id()); $es->set_sharing('owns'); $es->add_type($type->id()); $es->limit_tables(); $es->limit_fields(); $es->set_order('entity.last_modified DESC'); if (reason_user_has_privs($this->admin_page->user_id, 'edit')) { $state = 'Live'; $state_link_val = 'live'; } else { $state = 'Pending'; $state_link_val = 'pending'; } $ents = $es->run_one($type->id(), $state); $ents_count = count($ents); $name = $type->get_value('plural_name') ? $type->get_value('plural_name') : $type->get_value('name'); echo '<li class="' . $type->get_value('unique_name') . '" style="list-style-image:url(' . reason_get_type_icon_url($type) . ')">'; echo '<h4><a href="' . $this->admin_page->make_link(array('type_id' => $type->id(), 'cur_module' => 'Lister', 'state' => $state_link_val)) . '">' . $name . '</a> <span class="count">(' . $ents_count . ')</span></h4>' . "\n"; if (!empty($ents)) { echo '<div class="recent">' . "\n"; echo 'Recently edited:' . "\n"; echo '<ul>' . "\n"; $i = 1; foreach ($ents as $ent_id => $ent) { if ($i > 3) { break; } $name = strip_tags($ent->get_display_name()); if (empty($name)) { $name = '[unnamed]'; } echo '<li class="item' . $i . '"><a href="' . $this->admin_page->make_link(array('type_id' => $type->id(), 'id' => $ent_id, 'cur_module' => 'Editor')) . '">' . $name . '</a></li>' . "\n"; $i++; } echo '</ul>' . "\n"; echo '</div>' . "\n"; } echo '</li>' . "\n"; } echo '</ul>' . "\n"; echo '</div>' . "\n"; echo '</div>' . "\n"; }
function &set_cache() { if ($cache_class =& $this->get_cache_class()) { $this->_cache = carl_clone($cache_class); // localize a clone of the cache_class } return $this->_cache; }
/** * Adds a new field to the entity which is actually not a field of entity, but rather a field of * an entity which is related to the current entities. The entities selected by the ES will be * on the right side of the relationship. * Will return multiples of an entity if it has multiples of the same relationship. Not sure * how to change this. * @param string $rel_name the name of the relationship between the entities * @param string $table the table where the field is * @param string $field the name of the field to be selected * @param string $alias that alias for the field * @param mixed $limit_results true return only row for which the related value is defined * false to return all results even if the value does not exist * string or array to limit results to the values passed * @return void */ function add_right_relationship_field($rel_name, $table, $field, $alias, $limit_results = true) { if ($rel_name != "owns" && $rel_name != "borrows" && !empty($rel_name)) { $rel_type_id = relationship_id_of($rel_name); } elseif ($rel_name == 'owns' || $rel_name == 'borrows') { if (empty($this->type)) { $call_info = array_shift(debug_backtrace()); $code_line = $call_info['line']; $file = array_pop(explode('/', $call_info['file'])); $msg = 'entity selector method add_right_relationship_field called by ' . $file . ' on line ' . $code_line . ' on a generic "owns" or "borrows" relationship when the type has not been set on the entity selector.'; trigger_error($msg, WARNING); return false; } elseif ($rel_name == "owns") { $rel_type_id = get_owns_relationship_id(reset($this->type)); } elseif ($rel_name == "borrows") { $rel_type_id = get_borrows_relationship_id(reset($this->type)); } } if (empty($rel_type_id)) { trigger_error('add_right_relationship_field failed - an id could not be determined from the relationship name provided'); return false; } if ($limit_results === false) { $cur_es = carl_clone($this); $this->union = true; } $es = new entity_selector(); $es->add_table('relationship', 'relationship'); $es->add_table('__entity__', 'entity'); if ($table != 'entity') { $es->add_table($table); } $tables = $this->merge_tables($es); if (!empty($tables['relationship'])) { $r = $tables['relationship']; } else { $r = 'relationship'; } if (!empty($tables['__entity__'])) { $e = $tables['__entity__']; } else { $e = '__entity__'; } if ($table == 'entity') { $t = $e; } else { if (!empty($tables[$table])) { $t = $tables[$table]; } else { $t = $table; } } if ($e != $t) { $this->add_relation($e . '.id = ' . $t . '.id'); } $this->add_relation($e . '.id = ' . $r . '.entity_a'); $this->add_relation('entity.id = ' . $r . '.entity_b'); $this->add_relation($r . '.type = ' . $rel_type_id); $this->add_field($t, $field, $alias); if ($this->_env['restrict_site'] and !empty($this->_env['site'])) { $this->add_relation('(' . $r . '.site=0 OR ' . $r . '.site=' . addslashes($this->_env['site']) . ')'); } if ($limit_results === false) { $this->union_fields[end($this->fields)] = '0 as ' . $alias; $this->diff['fields'][] = array_diff_assoc($this->fields, $cur_es->fields); $this->diff['tables'][] = array_diff_assoc($this->tables, $cur_es->tables); $this->diff['relations'][] = array_diff_assoc($this->relations, $cur_es->relations); } elseif (is_string($limit_results) || is_array($limit_results)) { if (is_array($limit_results) && empty($limit_results)) { $this->add_relation('0 = 1'); } else { $limit_values = is_string($limit_results) ? array($limit_results) : $limit_results; array_walk($limit_values, 'db_prep_walk'); $this->add_relation($t . '.' . $field . ' IN (' . implode(',', $limit_values) . ')'); } } return array($alias => array('table_orig' => $table, 'table' => $t, 'field' => $field)); }
function _load_content_manager() { /* * load_content_manager(): finds the appropriate content manager for the entity * and does everything up to the error checks * */ reason_include_once('content_managers/default.php3'); $content_handler = $GLOBALS['_content_manager_class_names']['default.php3']; $type = new entity($this->admin_page->type_id); // set up a data member that init can get to after this method is called $this->entity_type = $type; if ($type->get_value('custom_content_handler')) { $include_file = $type->get_value('custom_content_handler'); if (!preg_match('/(php|php3)$/', $include_file)) { $include_file .= '.php3'; } $include_path = 'content_managers/' . $include_file; reason_include_once($include_path); $content_handler = $GLOBALS['_content_manager_class_names'][$include_file]; } /* Find editor who has 'normal' privs so that we can accurately communicate which fields are hidden to "normal" users. */ $editor = $this->_get_user_on_current_site('editor_user_role'); if (empty($editor)) { $editor = $this->_get_user_on_current_site('power_user_role'); } if (empty($editor)) { $editor = $this->_get_user_on_current_site('contribute_only_role'); } if (empty($editor)) { $editor = new entity($this->admin_page->user_id); } $fake_admin_page = carl_clone($this->admin_page); $fake_admin_page->user_id = $editor->id(); $fake_head_items = carl_clone($this->head_items); $disco_item = new $content_handler(); $disco_item->admin_page = $fake_admin_page; $disco_item->set_head_items($fake_head_items); $disco_item->prep_for_run($fake_admin_page->site_id, $fake_admin_page->type_id, $fake_admin_page->id, $fake_admin_page->user_id); $disco_item->init(); $disco_item->on_every_time(); $disco_item->pre_error_check_actions(); return $disco_item; }
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; }
public function contains_any_events_after($date) { if (!$this->contains_any_events()) { return false; } if (!empty($this->known_upper_limit) && $this->known_upper_limit > $date) { //echo '<strong>contains_any_events_after</strong>: req.date ('.$date.') before kul ('.$this->known_lower_limit.'); ret true<br />'; return true; } elseif (!empty($this->known_closest_date_after) && $this->known_closest_date_after < $date) { //echo '<strong>contains_any_events_after</strong>: req.date ('.$date.') after kcda ('.$this->known_closest_date_after.'); ret false<br />'; return false; } $test_es = carl_clone($this->base_es); $test_es->set_num(1); $test_es->add_relation('event.last_occurence > "' . reason_sql_string_escape($date) . '"'); $test_es->limit_fields(); $test_es->exclude_tables_dynamically(); $test_es->set_cache_lifespan($this->_get_cache_lifespan_meta()); //$test_es->optimize(''); //echo $test_es->get_one_query().'<br />'; $test_results = $test_es->run_one(); if (!empty($test_results)) { $result = current($test_results); //echo '<strong>contains_any_events_after</strong>: found event after req.date '.$date.'. id: '.$result->id().'; datetime: '.$result->get_value('datetime').'; ret true<br />'; $this->known_upper_limit = substr($result->get_value('datetime'), 0, 10); return true; } else { //echo '<strong>contains_any_events_after</strong>: no events found after req.date ('.$date.'); ret false<br />'; $this->known_closest_date_after = $date; return false; } }
function init() { if (!$this->should_run()) { trigger_error('Associator module needs an ID to run; none provided.'); return; } reason_include_once('classes/filter.php'); reason_include_once('content_listers/associate.php'); include_once CARL_UTIL_INC . 'basic/misc.php'; $this->head_items->add_javascript(JQUERY_URL, true); $this->head_items->add_stylesheet(REASON_ADMIN_CSS_DIRECTORY . 'assoc.css'); $this->head_items->add_javascript(WEB_JAVASCRIPT_PATH . 'table_update.js'); $this->head_items->add_javascript(WEB_JAVASCRIPT_PATH . 'associator.js'); $this->get_associations(); if (empty($this->associations[$this->admin_page->rel_id])) { trigger_error($this->admin_page->rel_id . ' is not a valid relationship type id'); die; } $current_assoc = $this->associations[$this->admin_page->rel_id]; $type = new entity($current_assoc['e_id']); // save the type entity in an object scope $this->rel_type = carl_clone($type); $this->admin_page->title = 'Selecting ' . $type->get_value('name'); $entity = new entity($this->admin_page->id); $user = new entity($this->admin_page->user_id); if (!$entity->user_can_edit_relationship($this->admin_page->rel_id, $user, $this->_rel_direction)) { $this->_locked = true; } elseif ($entity->relationship_has_lock($this->admin_page->rel_id, $this->_rel_direction) && reason_user_has_privs($this->admin_page->user_id, 'manage_locks')) { $this->_show_lock_info = true; } $this->get_views($type->id()); if (empty($this->views)) { //add generic lister if not already present $this->views = array(); } else { reset($this->views); $c = current($this->views); if ($c) { $lister = $c->id(); $this->admin_page->request['lister'] = $lister; } else { $lister = ''; } } $lister = isset($lister) ? $lister : ''; $this->get_viewer($this->admin_page->site_id, $type->id(), $lister); $this->filter = new filter(); $this->filter->set_page($this->admin_page); $this->filter->grab_fields($this->viewer->filters); }
/** * Uses the "archived" version of the es from before * applying filters to get a count of entities. */ function get_total_num_images_before_user_input() { $total_es = carl_clone($this->pre_user_input_es); $total_es->set_start(0); $total_es->set_num(false); return $total_es->get_one_count(); }