예제 #1
0
 function alter_es()
 {
     $type_id = id_of($this->type_unique_name);
     $this->es->set_order(table_of('datetime', $type_id) . ' DESC');
     $this->es->add_relation(table_of('minutes_status', $type_id) . ' = "published"');
 }
예제 #2
0
		function do_filters_search()
		{
			if(!empty($this->request['search']))
			{
				$search_term = $this->request['search'];
				$regexp = '/(?:\"(.+?)\"|([^\*\"\s]+))/';
				preg_match_all($regexp,$search_term,$matches);
				
				$search_term_array = array();
				foreach ($matches[1] as $chunk)
				{
					if (!empty($chunk))	$search_term_array[] = trim($chunk);
				}
				
				foreach ($matches[2] as $chunk)
				{
					if (!empty($chunk))	$search_term_array[] = trim($chunk);
				}
				$search_array = array();
				
				foreach ($search_term_array as $chunk)
				{
					$sub_search_array = array();
					foreach($this->search_fields as $field)
					{
						$table_field = '';
						if(false === strpos($field,'.'))
							$table_field = table_of($field,$this->type);
						if(empty($table_field))
							$table_field = $field;
						$sub_search_array[] = $table_field . ' LIKE "%'.strtr(addslashes($chunk),array('*'=>'%')).'%"';
					}
					$search_array[] = '('.implode(' OR ',$sub_search_array).')';
				}
				if (!empty($search_array))
				{
					$this->es->add_relation('('.implode(' AND ', $search_array).')');
				}
			}
			foreach($this->allowable_psearch_fields as $psearch_frag => $psearch_data)
			{
				if (!empty($this->request['search_' . $psearch_frag]))
				{
					$psearch_string = str_replace('*','%',addslashes($this->request['search_' . $psearch_frag]));
					$this->es->add_relation('(' . $psearch_data['field'] . ' LIKE "' . $psearch_string . '")');
				}
			}
		}
예제 #3
0
		function get_policy_children($policy)
		{
			$es = new entity_selector();
			$es->add_type(id_of('policy_type'));
			$es->add_relation('entity.id != "'.$policy->id().'"');
			$es->add_relation( table_of('show_hide', id_of( 'policy_type' )) .' != "hide"' );
			$es->add_left_relationship($policy->id(),relationship_id_of('policy_parent'));
			$es->set_order('sortable.sort_order ASC');
			return $es->run_one();
		}
예제 #4
0
 function apply_order_and_limits(&$es)
 {
     $limit_tables = true;
     if (isset($this->viewer_id) && !empty($this->viewer_id)) {
         $viewer = new entity($this->viewer_id);
         if ($viewer->get_values() && $viewer->get_value('type') == id_of('view')) {
             $viewer_default_sort = $viewer->get_value('default_sort');
             if (!empty($viewer_default_sort)) {
                 $limit_tables = false;
             }
         }
     }
     if (!empty($this->admin_page->request['order_by'])) {
         $alias = isset($this->alias[$this->admin_page->request['order_by']]) ? $this->alias[$this->admin_page->request['order_by']] : '';
         if ($alias) {
             $table = $alias['table'] . '.' . $alias['field'];
             $table_name = $alias['table_orig'];
         } else {
             $table = table_of($this->admin_page->request['order_by'], $this->type_id);
             $table_name = substr($table, 0, strpos($table, '.' . $this->admin_page->request['order_by']));
         }
         if ($table) {
             $es->set_order($table . ' ' . $this->admin_page->request['dir']);
             if (!$this->check_filters() && $limit_tables) {
                 $es->limit_tables($table_name);
             }
             // only limit if filters are not being used
         }
     } elseif (!$this->check_filters() && $limit_tables) {
         $es->limit_tables();
     }
     // only limit if filters are not being used
 }
예제 #5
0
			/**
			 * Grabs the sort from known info and adds the appropriate sorting info to the entity_selector
			 */
			function grab_sort() // {{{
			{
				if(!empty($this->order_by))
				{
					$alias = isset( $this->alias[ $this->order_by ] ) ? $this->alias[ $this->order_by ] : '';
					if( $alias )  //first, check aliases
						$table = $alias[ 'table' ] . '.' . $alias[ 'field' ];
					else //then check normal values
					{
						// chop table name if it is present
						$orderby = (strrchr($this->order_by, ".")) ? substr(strrchr($this->order_by, "."), 1) : $this->order_by;
						$table = table_of( $orderby , $this->type_id);
					}
					if($table)  //if we've found one, add the relation
						$this->es->set_order($table . ' ' . $this->dir);
				}
			}
예제 #6
0
 public function contains_any_events_before($date)
 {
     if (!$this->contains_any_events()) {
         return false;
     }
     if (!empty($this->known_lower_limit) && $this->known_lower_limit < $date) {
         //echo '<strong>contains_any_events_before</strong>: req.date ('.$date.') after kll ('.$this->known_lower_limit.'); ret true<br />';
         return true;
     } elseif (!empty($this->known_closest_date_before) && $this->known_closest_date_before > $date) {
         //echo '<strong>contains_any_events_before</strong>: req.date ('.$date.') before kcdb ('.$this->known_closest_date_before.'); ret false<br />';
         return false;
     }
     $test_es = carl_clone($this->base_es);
     $test_es->set_num(1);
     $test_es->add_relation(table_of('datetime', id_of('event_type')) . ' < "' . 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_results = $test_es->run_one();
     if (!empty($test_results)) {
         $result = current($test_results);
         //echo '<strong>contains_any_events_before</strong>: found event before req.date '.$date.'. id: '.$result->id().'; datetime: '.$result->get_value('datetime').'; ret true<br />';
         $date = prettify_mysql_datetime($result->get_value('datetime'), 'Y-m-d');
         $this->known_lower_limit = carl_date('Y-m-d', strtotime($date . ' -1 day'));
         return true;
     } else {
         //echo '<strong>contains_any_events_before</strong>: no events found before req.date ('.$date.'); ret false<br />';
         $this->known_closest_date_before = $date;
         return false;
     }
 }
예제 #7
0
	/**
	 * Is a given event acceptable to show in the calendar?
	 * @param object $event entity
	 * @return boolean
	 */
	function event_ok_to_show($event)
	{
		$id = $event->id();
		if (!isset($this->_ok_to_show[$id]))
		{
			$sites = $this->_get_sites();
			if(is_array($sites)) $es = new entity_selector(array_keys($sites));
			else $es = new entity_selector($sites->id());
			$es->add_type(id_of('event_type'));
			$es->add_relation('entity.id = "'.$id.'"');
			$es->add_relation(table_of('show_hide', id_of('event_type')). ' = "show"');
			$es->set_num(1);
			$es->limit_tables(get_table_from_field('show_hide', id_of('event_type')));
			$es->limit_fields();
			if($this->_get_sharing_mode() == 'shared_only') $es->add_relation('entity.no_share != 1');
			$this->_ok_to_show[$id] = ($es->run_one());
		}
		return $this->_ok_to_show[$id];
	}
예제 #8
0
 /**
  * Limits entity selector to fields specified - note that the entity id will always be selected
  * The entity table will always be included in an entity selector even if not passed to this function
  *
  * @param mixed fields - array of field names or string with a single field name in format entitytablename.fieldname
  * @return void
  */
 function limit_fields($fields = '')
 {
     if (is_array($fields)) {
         $field_array = $fields;
     } elseif (!empty($fields)) {
         $field_array[] = $fields;
     } else {
         $field_array = '';
     }
     if (is_array($field_array)) {
         foreach ($field_array as $field) {
             if (isset($this->type[0]) && strpos($field, ".") === FALSE && ($tablewithfield = table_of($field, $this->type[0]))) {
                 $this->limit_fields[] = $tablewithfield;
             } else {
                 $this->limit_fields[] = $field;
             }
         }
     } else {
         $this->limit_fields = array();
     }
 }
예제 #9
0
 /**
  * Sets a sort order for the associated items if a sort order was passed in the url
  * 
  * @return boolean did it set a custom order
  */
 function assoc_viewer_order_by(&$ass_es)
 {
     if (!empty($this->admin_page->request['order_by'])) {
         // first, check aliases
         $alias = isset($this->alias[$this->admin_page->request['order_by']]) ? $this->alias[$this->admin_page->request['order_by']] : '';
         if ($alias) {
             $table = $alias['table'] . '.' . $alias['field'];
         } else {
             $table = table_of($this->admin_page->request['order_by'], $this->type_id);
         }
         // if we found something, add the relation
         if ($table) {
             if ('ASC' == $this->admin_page->request['dir'] || 'DESC' == $this->admin_page->request['dir']) {
                 $ass_es->set_order($table . ' ' . $this->admin_page->request['dir']);
                 return true;
             }
         }
     }
     return false;
 }