Ejemplo n.º 1
0
function fi_kilonkipinat_events_compute_last_event(&$parent)
{
    $qb = fi_kilonkipinat_events_event_dba::new_query_builder();
    if (is_a($parent, 'fi_kilonkipinat_events_event_dba')) {
        $qb->add_constraint('up', 'INTREE', $parent->id);
    } elseif (is_a($parent, 'midcom_baseclasses_database_topic')) {
        $qb->add_constraint('topic', '=', $parent->id);
    } else {
        return false;
    }
    // Avoid problems with events too close to the epoch (highly unlikely usage scenario in any case)
    $qb->add_constraint('start', '>', '1972-01-02 00:00:00');
    $qb->add_order('end', 'DESC');
    $qb->set_limit(1);
    if ($_MIDCOM->auth->request_sudo()) {
        $result = $qb->execute();
        $_MIDCOM->auth->drop_sudo();
    } else {
        $result = $qb->execute();
    }
    unset($qb);
    if (empty($result)) {
        return false;
    }
    return $result[0];
}
Ejemplo n.º 2
0
 /**
  * The handler for the index event.
  *
  * @param mixed $handler_id the array key from the request array
  * @param array $args the arguments given to the handler
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_index($handler_id, $args, &$data)
 {
     $this->_request_data['name'] = "fi.kilonkipinat.events";
     $this->_update_breadcrumb_line($handler_id);
     $kisa_config = $this->_config->get('kisa');
     $_MIDCOM->set_pagetitle("{$this->_topic->extra}");
     $qb_trips = fi_kilonkipinat_events_event_dba::new_query_builder();
     //$qb_trips->add_constraint('topic', '=', $this->_topic->id);
     $qb_trips->add_constraint('type', '>=', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_GENERIC);
     $qb_trips->add_constraint('type', '<', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_MEETING_GENERIC);
     if ($kisa_config == 0) {
         $qb_trips->add_constraint('kisa', '<=', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 1) {
         $qb_trips->add_constraint('kisa', '<', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 2) {
         $qb_trips->add_constraint('kisa', '>=', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 3) {
         $qb_trips->add_constraint('kisa', '>', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     }
     $qb_trips->add_constraint('end', '>', date('Y-m-d H:i:s', time()));
     $qb_trips->add_order('start');
     if (!$_MIDGARD['user']) {
         $qb_trips->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC);
     }
     $trips = $qb_trips->execute();
     $qb_meetings = fi_kilonkipinat_events_event_dba::new_query_builder();
     //$qb_meetings->add_constraint('topic', '=', $this->_topic->id);
     $qb_meetings->add_constraint('type', '>=', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_MEETING_GENERIC);
     $qb_meetings->add_constraint('type', '<=', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_MEETING_ANNUAL);
     if ($kisa_config == 0) {
         $qb_meetings->add_constraint('kisa', '<=', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 1) {
         $qb_meetings->add_constraint('kisa', '<', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 2) {
         $qb_meetings->add_constraint('kisa', '>=', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 3) {
         $qb_meetings->add_constraint('kisa', '>', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     }
     $qb_meetings->add_constraint('end', '>', date('Y-m-d H:i:s', time()));
     $qb_meetings->add_order('start');
     if (!$_MIDGARD['user']) {
         $qb_meetings->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC);
     }
     $meetings = $qb_meetings->execute();
     $this->_trips = $trips;
     $this->_meetings = $meetings;
     return true;
 }
Ejemplo n.º 3
0
 public function _load_object($handler_id, $args, &$data)
 {
     $qb = fi_kilonkipinat_events_event_dba::new_query_builder();
     //$qb->add_constraint('topic', '=', $this->_request_data['content_topic']->id);
     $qb->add_constraint('guid', '=', $args[0]);
     $qb->set_limit(1);
     $objects = $qb->execute();
     if (is_array($objects) && count($objects) > 0) {
         $this->_object = $objects[0];
         $this->_event = $this->_object;
         if (!$_MIDGARD['user'] && $this->_event->visibility == FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_SECURE) {
             $_MIDCOM->auth->require_valid_user();
         }
     } else {
         debug_push_class(__CLASS__, __FUNCTION__);
         debug_pop();
         $_MIDCOM->generate_error(MIDCOM_ERRNOTFOUND, 'Failed to load event, cannot continue. Last Midgard error was: ' . midcom_application::get_error_string());
         // This will exit.
     }
     return $this->_object;
 }
Ejemplo n.º 4
0
 /**
  * Prepare event listing query builder that takes all configured filters into account
  *
  * @access static
  */
 static function prepare_event_qb(&$data, &$config)
 {
     // Load filters
     $filters = fi_kilonkipinat_events_viewer::prepare_filters($config);
     $qb = fi_kilonkipinat_events_event_dba::new_query_builder();
     if (!$_MIDGARD['user']) {
         $qb->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC);
     }
     // Add node or root event constraints
     if ($config->get('list_from_master')) {
         // List under an event tree by up field
         $qb->add_constraint('up', 'INTREE', $data['master_event']);
     } else {
         $list_from_folders = $config->get('list_from_folders');
         if ($list_from_folders) {
             // We have specific folders to list from, therefore list from them and current node
             $guids = explode('|', $config->get('list_from_folders'));
             $guids_array = array();
             $guids_array[] = $data['content_topic']->guid;
             foreach ($guids as $guid) {
                 if (!$guid || !mgd_is_guid($guid)) {
                     // Skip empty and broken guids
                     continue;
                 }
                 $guids_array[] = $guid;
             }
             /**
              * Ref #1776, expands GUIDs before adding them as constraints, should save query time
              */
             $topic_ids = array();
             $topic_ids[] = $data['content_topic']->id;
             if (!empty($guids_array)) {
                 $mc = midcom_db_topic::new_collector('sitegroup', $_MIDGARD['sitegroup']);
                 $mc->add_constraint('guid', 'IN', $guids_array);
                 $mc->add_value_property('id');
                 $mc->execute();
                 $keys = $mc->list_keys();
                 foreach ($keys as $guid => $dummy) {
                     $topic_ids[] = $mc->get_subkey($guid, 'id');
                 }
                 unset($mc, $keys, $guid, $dummy);
             }
             $qb->add_constraint('topic', 'IN', $topic_ids);
         } else {
             // List from current node only
             $qb->add_constraint('topic', '=', $data['content_topic']->id);
         }
     }
     // Add filtering constraint
     if (isset($filters['type_filter'])) {
         $qb->add_constraint('type', '=', (int) $filters['type_filter']);
     }
     if (isset($filters['other'])) {
         // Handle other direct field mapping constraints
         foreach ($filters['other'] as $field => $filter) {
             $qb->add_constraint($field, '=', $filter);
         }
     }
     // Handle category filter
     if (isset($filters['category_filter'])) {
         $qb->add_constraint('category', 'LIKE', "%|{$filters['category_filter']}|%");
     }
     return $qb;
 }
Ejemplo n.º 5
0
 /**
  * @param mixed $handler_id The ID of the handler.
  * @param Array $args The argument list.
  * @param Array &$data The local request data.
  * @return boolean Indicating success.
  */
 function _handler_upcoming($handler_id, $args, &$data)
 {
     $this->_request_data['name'] = "fi.kilonkipinat.events";
     $_MIDCOM->skip_page_style = true;
     $_MIDCOM->set_pagetitle("{$this->_topic->extra}");
     $this->_load_datamanager();
     $limit = 10;
     if (isset($args[0]) && (int) $args[0] > 0) {
         $limit = (int) $args[0];
     }
     // Get the requested date range
     // TODO: Check format as YYYY-MM-DD via regexp
     $start = time();
     $qb_events = fi_kilonkipinat_events_event_dba::new_query_builder();
     //$qb_events->add_constraint('topic', '=', $this->_topic->id);
     $kisa_config = $this->_config->get('kisa');
     if ($kisa_config == 0) {
         $qb_events->add_constraint('kisa', '<=', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 1) {
         $qb_events->add_constraint('kisa', '<', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 2) {
         $qb_events->add_constraint('kisa', '>=', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     } elseif ($kisa_config == 3) {
         $qb_events->add_constraint('kisa', '>', FI_KILONKIPINAT_EVENTS_EVENT_KISA_BOTH);
     }
     if ($handler_id == 'upcoming_trips') {
         $qb_events->add_constraint('type', '>=', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_GENERIC);
         $qb_events->add_constraint('type', '<', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_MEETING_GENERIC);
     } else {
         $qb_events->add_constraint('type', '>=', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_MEETING_GENERIC);
         $qb_events->add_constraint('type', '<=', FI_KILONKIPINAT_EVENTS_EVENT_TYPE_MEETING_ANNUAL);
     }
     $qb_events->add_constraint('end', '>=', date('Y-m-d H:i:s', $start));
     if (!$_MIDGARD['user']) {
         $qb_events->add_constraint('visibility', '=', FI_KILONKIPINAT_EVENTS_EVENT_VISIBILITY_PUBLIC);
     }
     $qb_events->add_order('start');
     $qb_events->set_limit($limit);
     $events = $qb_events->execute();
     $this->_events = $events;
     return true;
 }