function init($args = array())
 {
     parent::init($args);
     if ($this->controller->get_current_step() != 'SelectItems') {
         return;
     }
     if ($this->controller->get_form_data('selected_publications') != '' || $this->controller->get_form_data('events_start_date') != '') {
         $this->add_element('select_instructions', 'comment', array('text' => '<p>Items from the publications and calendar dates which you picked are displayed below. Select the posts and events that you would like to include in your newsletter from the lists below.</p>'));
     }
     if ($this->controller->get_form_data('selected_publications') != '') {
         $pubs = $this->controller->get_form_data('selected_publications');
         $this->add_element('pub_items_header', 'comment', array('text' => '<h2 class="region">Posts</h2>'));
         foreach ($pubs as $pub) {
             $post_options = array();
             $ph_new = new PublicationHelper($pub);
             if ($startDate = $this->controller->get_form_data('publication_start_date')) {
                 $ph_new->set_start_date($startDate);
             }
             if ($endDate = $this->controller->get_form_data('publication_end_date')) {
                 $ph_new->set_end_date($endDate);
             }
             $pub_posts = $ph_new->get_published_items();
             $page_of_publication = $ph_new->get_right_relationship('page_to_publication');
             if ($pub_posts) {
                 foreach ($pub_posts as $pub_post) {
                     $available_posts[$pub][$pub_post->get_value('id')] = array('id' => $pub_post->get_value('id'), 'name' => $pub_post->get_value('name'), 'date_released' => $pub_post->get_value('datetime'), 'created_by' => $pub_post->get_value('created_by'), 'url' => reason_get_page_url($page_of_publication[0]->get_value('id')) . "?story_id=" . $pub_post->get_value('id'));
                 }
             }
             if (!empty($available_posts)) {
                 if (empty($available_posts[$pub])) {
                     $this->add_element("pub_items_number_{$pub}", 'comment', array('text' => '<p>No live posts were found for the publication "' . $ph_new->get_value('name') . '".</p>'));
                 } else {
                     $count = count($available_posts[$pub]);
                     $text = "{$count}" . ($count > 1 ? ' posts were' : ' post was');
                     $text .= ' found for the publication "' . $ph_new->get_value('name') . '"';
                     foreach ($available_posts[$pub] as $post) {
                         $post_options[$post['id'] . '_post'] = $post['name'] . ' (<a target="_blank" href="' . $post['url'] . '">link</a>)';
                         //						$this->add_element($item['id'].'_info', 'comment', array('text' => '<p>Date released: '.$item['date_released'].'</p>'));
                     }
                     $this->add_element("pub_posts_group_{$pub}", 'checkboxgroup', array('options' => $post_options));
                     $this->set_display_name("pub_posts_group_{$pub}", $text);
                 }
             } else {
                 $this->add_element("pub_items_none_{$pub}", 'comment', array('text' => '<p>No posts were found for "' . $ph_new->get_value('name') . '" during the selected timeframe.</p>'));
             }
         }
     }
     if ($this->controller->get_form_data('events_start_date') != '') {
         $site_id = (int) $_REQUEST['site_id'];
         $site = new entity($site_id);
         $start_date = $this->controller->get_form_data('events_start_date');
         $end_date = $this->controller->get_form_data('events_end_date');
         $end_date = !empty($end_date) ? $end_date : date('Y-m-d');
         $cal = new reasonCalendar(array('site' => $site, 'start_date' => $start_date, 'end_date' => $end_date));
         $cal->run();
         $events = $cal->get_all_events();
         $days = $cal->get_all_days();
         $this->add_element('events_header', 'comment', array('text' => '<h2 class="region">Calendar events</h2>'));
         if ($days) {
             // This is a bit of a hack. We want to know the number of deepest-level elements
             // _before_ we've  iterated through the array, creating elements for each deepest-level
             // element... hence the double foreach.
             $count = 0;
             foreach ($days as $day => $event_ID_array) {
                 foreach ($event_ID_array as $event_item) {
                     $count++;
                 }
             }
             $text = "<p>{$count}" . ($count > 1 ? ' calendar events were found.</p>' : ' calendar event was found.</p>');
             $this->add_element('events_number', 'comment', array('text' => $text));
             foreach ($days as $day => $event_ID_array) {
                 $event_options = array();
                 $events_from_today = array();
                 foreach ($event_ID_array as $event_ID) {
                     $events_from_today[$event_ID] = $events[$event_ID];
                 }
                 uasort($events_from_today, "sort_events");
                 foreach ($events_from_today as $event_id => $event_item) {
                     $prettyDate = date("g:i a", strtotime($event_item->get_value('datetime')));
                     $eHelper = new EventHelper();
                     @$eHelper->set_page_link($event_item);
                     $eventURL = $event_item->get_value('url') . date("Y-m-d", strtotime($event_item->get_value('datetime')));
                     $event_options[$event_id . '_event'] = '<strong>' . $prettyDate . '</strong> ' . $event_item->get_value('name') . ' (<a target="_blank" href="' . $eventURL . '">link</a>)';
                 }
                 $this->add_element('events_group_day_' . $day, 'checkboxgroup_no_sort', array('options' => $event_options));
                 $rows[] = date("D, M j Y", strtotime($day));
                 $elements_to_add_to_group['events_group_day_' . $day] = 'events_group_day_' . $day;
             }
             $args = array('rows' => $rows, 'use_element_labels' => false, 'use_group_display_name' => false, 'wrapper_class' => 'events_wrapper');
             $this->add_element_group('wrappertable', 'events_group', $elements_to_add_to_group, $args);
         } else {
             $this->add_element('events_number', 'comment', array('text' => '<p>No events were found.</p>'));
         }
     }
 }
Example #2
0
 /**
  *	Discovers potential conflicts -- can be used to reduce the possibility of duplicate events in Reason
  * 
  * Please note: this function is currently experimental.
  * It may not work precisely as advertised, and may not be particularly fast.
  *
  * @author Matt Ryan
  * @param array $values 
  * @return array $similar_entities
  */
 function find_similar_events($values = array())
 {
     if (empty($values) && !empty($this->disco_form)) {
         $values = $this->disco_form->get_values();
     }
     if (empty($values)) {
         $values = $this->get_event_values();
     }
     if (empty($values)) {
         trigger_error('Programmer error: no event values available for reasonEvent::find_errors()');
     }
     if (empty($values['datetime']) || $values['datetime'] == '0000-00-00 00:00:00') {
         trigger_error('Values must contain a valid datetime in reasonEvent::find_similar_events()');
         return false;
     }
     reason_include_once('classes/calendar.php');
     // find events that occur on that day at that time
     $start_date = substr($values['datetime'], 0, 10);
     $init_array = array('start_date' => $start_date, 'view' => 'daily', 'automagic_window_snap_to_nearest_view' => true);
     $cal = new reasonCalendar($init_array);
     $cal->run();
     $days = $cal->get_all_days();
     $all_events = $cal->get_all_events();
     $similar_events = array();
     $time = substr($values['datetime'], 11);
     if (!empty($days)) {
         reset($days);
         $day = current($days);
         if (!empty($day)) {
             foreach ($day as $id) {
                 if ($id != $values['id'] && substr($all_events[$id]->get_value('datetime'), 11) == $time) {
                     $percent = 0;
                     similar_text($values['name'], $all_events[$id]->get_value('name'), $percent);
                     //echo $all_events[$id]->get_value('name').': '.$percent.'%<br />';
                     if ($percent > 55) {
                         $similar_events[$id] =& $all_events[$id];
                         $similar_events[$id]->set_value('event_similarity', $percent);
                     }
                 }
             }
         }
     }
     return $similar_events;
 }
	/**
	 * Get the event ocurrences for a given category
	 *
	 * This is the method to use when the param show_individual_occurrences is true
	 *
	 * @param entity $category
	 * @return array of dates to entities
	 */
	function _get_event_ocurrences_for_category($category)
	{
		$site = new entity($this->site_id);
		
		$cal = new reasonCalendar(array('site'=>$site,'ideal_count'=>$this->params['max_num_per_category'], 'automagic_window_snap_to_nearest_view'=>false,'categories'=>array($category->id()=>$category)));
		$cal->run();
		$event_days = $cal->get_all_days();
		$event_entities = $cal->get_all_events();
		$ret = array();
		foreach($event_days as $day=>$ids)
		{
			foreach($ids as $id)
			{
				$ret[$day][$id] = $event_entities[$id];
			}
		}
		return $ret;
	}
 * include dependencies
 */
include_once 'reason_header.php';
reason_include_once('classes/entity_selector.php');
reason_include_once('classes/calendar.php');
reason_include_once('classes/admin/admin_page.php');
if (!reason_check_authentication()) {
    header('HTTP/1.1 400 Bad Request');
    echo '<html><head><title>Calendar did not work</title><meta name="robots" content="none" /></head><body><h1>Calendar did not work</h1><p>You must be logged in to use this script.</p></body></html>';
} else {
    if (!empty($_REQUEST['date'])) {
        // normalize the date format
        $stamp = strtotime($_REQUEST['date']);
        $date = date('Y-m-d', $stamp);
        // Get and sort the events
        $calendar = new reasonCalendar(array('start_date' => $date, 'end_date' => $date, 'view' => 'daily', 'show_statuses' => array('show', 'tentative', 'cancelled')));
        $calendar->run();
        $events = $calendar->get_all_events();
        usort($events, 'compare_times');
        // Figure out the URL for the borrow action
        parse_str(trim($_REQUEST['params'], '?'), $params);
        $editing_id = $params['id'];
        $params['cur_module'] = 'DoBorrow';
        echo '<h4>Other events for ' . date('l, F jS', $stamp) . ':</h4>';
        if (count($events)) {
            // Ask the admin page class for the token that will allow us
            // to complete the borrow action.
            $admin = new AdminPage();
            $params['admin_token'] = $admin->get_admin_token();
            echo '<p>Click an event to add it to the <em>' . $_REQUEST['site'] . '</em> calendar:</p>';
            echo '<ul class="preview_list">';
Example #5
0
	/**
	 * Set up and run a calendar with a given initialization array
	 * @param array $init_array
	 * @return object reason calendar
	 */
	function _get_runned_calendar($init_array)
	{
		$calendar = new reasonCalendar($init_array);
		$calendar->run();
		return $calendar;
	}