Exemple #1
0
 /**
  * Locates the root event
  */
 public static function find_root_event()
 {
     if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
         midcom::get('componentloader')->load_graceful('org.openpsa.calendar');
         //Doublecheck
         if (!midcom::get('componentloader')->is_loaded('org.openpsa.calendar')) {
             return false;
         }
     }
     $data = midcom_baseclasses_components_configuration::get('org.openpsa.calendar');
     //Check if we have already initialized
     if (isset($data['calendar_root_event']) && is_object($data['calendar_root_event'])) {
         return $data['calendar_root_event'];
     }
     $root_event = false;
     $root_guid = $data['config']->get('calendar_root_event');
     if (mgd_is_guid($root_guid)) {
         $root_event = org_openpsa_calendar_event_dba::get_cached($root_guid);
     } else {
         // Check for calendar event tree.
         $qb = org_openpsa_calendar_event_dba::new_query_builder();
         $qb->add_constraint('title', '=', '__org_openpsa_calendar');
         $qb->add_constraint('up', '=', '0');
         $ret = $qb->execute();
         if (is_array($ret) && count($ret) > 0) {
             $root_event = $ret[0];
             $siteconfig = org_openpsa_core_siteconfig::get_instance();
             $topic_guid = $siteconfig->get_node_guid('org.openpsa.calendar');
             if ($topic_guid) {
                 $topic = new midcom_db_topic($topic_guid);
                 $topic->set_parameter('org.openpsa.calendar', 'calendar_root_event', $root_event->guid);
             }
         } else {
             debug_add("OpenPSA Calendar root event could not be found", MIDCOM_LOG_ERROR);
             //Attempt to auto-initialize
             $root_event = self::create_root_event();
         }
     }
     $data['calendar_root_event'] = $root_event;
     return $root_event;
 }