/** * Prepare occurrences output * * @param string $tagdata Tagdata * @param array $data Array of data * @param bool $include_default Include the default entry_id when fetching weblog data? * @return string */ protected function prep_occurrences_output($tagdata, $data, $include_default = TRUE) { $tagdata = $this->fix_conditional_date_escaping('occurrence', $tagdata); // ------------------------------------- // Ensure $this->CDT is ready // ------------------------------------- $this->load_calendar_datetime(); if (empty($data->dates)) { return $tagdata; } $output = ''; // ------------------------------------- // Put the items in order // ------------------------------------- foreach ($data->dates as $ymd => $times) { ksort($data->dates[$ymd]); } ksort($data->dates); //-------------------------------------------- // order arrays for later multi sorting //-------------------------------------------- $calendar_orderby_params = array('event_start_date', 'occurrence_start_date'); $orders = explode('|', $this->P->value('orderby')); $sorts = explode('|', $this->P->value('sort')); $calendar_orders = array(); $calendar_order_data = array(); foreach ($orders as $k => $order) { if (in_array($order, $calendar_orderby_params)) { $sort = isset($sorts[$k]) ? $sorts[$k] : 'desc'; $calendar_orders[$order] = $sort; $calendar_order_data[$order] = array(); } } // ------------------------------------- // Are prior_ or upcoming_ limits in effect? // ------------------------------------- $prior_limit = $this->P->value('prior_occurrences_limit') !== FALSE ? $this->P->value('prior_occurrences_limit') : FALSE; $upcoming_limit = $this->P->value('upcoming_occurrences_limit') !== FALSE ? $this->P->value('upcoming_occurrences_limit') : FALSE; if ($prior_limit !== FALSE or $upcoming_limit !== FALSE) { $priors = array(); $upcoming = array(); //set date to current $this->CDT->set_date_to_now(); foreach ($data->dates as $ymd => $info) { //yeterday or before if ($ymd < $this->CDT->ymd) { $priors[$ymd] = $info; } elseif ($ymd == $this->CDT->ymd) { //we need to check all hours and minutes :/ foreach ($info as $time => $time_data) { $temp_end_hour = $time_data['end_date']['hour'] + ($time_data['end_date']['pm'] ? 12 : 0); $temp_end_minute = $time_data['end_date']['minute']; //if this is an all day item and we are still in this day, its current if ($time_data['all_day'] == TRUE) { $upcoming[$ymd][$time] = $time_data; } else { if ($temp_end_hour > $this->CDT->hour() or $temp_end_hour == $this->CDT->hour() and $temp_end_minute > $this->CDT->minute()) { $upcoming[$ymd][$time] = $time_data; } else { $priors[$ymd][$time] = $time_data; } } } } else { $upcoming[$ymd] = $info; } } //slice out our limits if ($prior_limit !== FALSE) { $priors = $this->apply_occurrences_limit($priors, $prior_limit, 0, 'prior'); //$priors = array_slice(array_reverse($priors, TRUE), 0, $prior_limit, TRUE); } if ($upcoming_limit !== FALSE) { $upcoming = $this->apply_occurrences_limit($upcoming, $upcoming_limit, 0, 'upcoming'); //$upcoming = array_slice($upcoming, 0, $upcoming_limit, TRUE); } //this has to be recursive because we can have the same $YMD happening if its today's date $data->dates = array_merge_recursive($priors, $upcoming); } //-------------------------------------------- // get default data from parent entry_id //-------------------------------------------- if (!isset($this->cache['entry_info'])) { $this->cache['entry_info'] = array(); } //we need some extra data about this entry so we can parse occurrences items if (!isset($this->cache['entry_info'][$data->default_data['entry_id']])) { $entry_info_query = ee()->db->query("SELECT \tct.title, ct.url_title, ct.author_id, ct.status, m.screen_name, m.username\n\t\t\t\t FROM\t\t{$this->sc->db->channel_titles} as ct\n\t\t\t\t LEFT JOIN\texp_members as m\n\t\t\t\t ON\t\t\tct.author_id = m.member_id\n\t\t\t\t WHERE\t\tct.entry_id = " . ee()->db->escape_str($data->default_data['entry_id'])); if ($entry_info_query->num_rows() > 0) { $this->cache['entry_info'][$data->default_data['entry_id']] = $entry_info_query->row_array(); } else { $this->cache['entry_info'][$data->default_data['entry_id']] = array(); } } $entry_info = $this->cache['entry_info'][$data->default_data['entry_id']]; // ------------------------------------- // Grab entry IDs from the occurrences // ------------------------------------- foreach ($data->occurrences as $ymd => $times) { foreach ($times as $time => $info) { if ($info['entry_id'] != $data->default_data['entry_id'] and !isset($ids[$info['entry_id']])) { $ids[$ymd] = $info['entry_id']; } } } $tagdatas = array(); $tagdatas[$data->default_data['entry_id']] = $tagdata; //this will probably only happen for edited occurrences if (!empty($ids)) { // ------------------------------------- // Add the "parent" entry id for default data // ------------------------------------- $ids[0] = $data->default_data['entry_id']; //ee()->TMPL_orig = clone ee()->TMPL; $tagdata = LD . 'occurrences id="' . LD . 'entry_id' . RD . '"' . RD . $tagdata . LD . T_SLASH . 'occurrences' . RD; // ---------------------------------------- // Invoke Channel class // ---------------------------------------- if (!class_exists('Channel')) { require PATH_MOD . '/channel/mod.channel.php'; } $channel = new Channel(); //need to remove limit here so huge amounts of events work $channel->limit = 1000000; // -------------------------------------------- // Invoke Pagination for EE 2.4 and Above // -------------------------------------------- $channel = $this->add_pag_to_channel($channel); // ------------------------------------- // Prepare parameters // ------------------------------------- ee()->TMPL->tagparams['entry_id'] = implode('|', $ids); ee()->TMPL->tagparams['weblog'] = CALENDAR_EVENTS_CHANNEL_NAME; ee()->TMPL->tagparams['channel'] = CALENDAR_EVENTS_CHANNEL_NAME; // ------------------------------------- // Pre-process related data // ------------------------------------- if (version_compare($this->ee_version, '2.6.0', '<')) { ee()->TMPL->tagdata = ee()->TMPL->assign_relationship_data($tagdata); } ee()->TMPL->var_single = array_merge(ee()->TMPL->var_single, ee()->TMPL->related_markers); ee()->TMPL->var_single['entry_id'] = 'entry_id'; // ------------------------------------- // Execute needed methods // ------------------------------------- $channel->fetch_custom_channel_fields(); $channel->fetch_custom_member_fields(); // -------------------------------------------- // Pagination Tags Parsed Out // -------------------------------------------- $channel = $this->fetch_pagination_data($channel); // ------------------------------------- // Add occurrence_ prefix to custom fields // ------------------------------------- foreach ($channel->cfields as $sid => $fields) { foreach ($fields as $name => $fid) { $channel->cfields[$sid]['occurrence_' . $name] = $fid; unset($channel->cfields[$sid][$name]); } } // ------------------------------------- // Querification // ------------------------------------- $channel->build_sql_query(); if ($channel->sql == '') { return $this->no_results(); } $channel->query = ee()->db->query($channel->sql); if ($channel->query->num_rows() == 0) { //ee()->TMPL->log_item('Calendar: Channel module says no results, bailing'); return $this->no_results(); } $channel->query->result = $channel->query->result_array(); // ------------------------------------- // Trim IDs and build events // ------------------------------------- $new_ids = array(); foreach ($channel->query->result as $k => $row) { $new_ids[$row['entry_id']] = $row['entry_id']; } if (empty($new_ids)) { return $this->no_results(); } $occurrence_data = $this->data->fetch_event_occurrences($data->default_data['entry_id']); // ------------------------------------- // Turn these IDs into events // ------------------------------------- $events = array(); if (!class_exists('Calendar_event')) { require_once CALENDAR_PATH . 'calendar.event.php'; } $calendars = array(); $start_ymd = $this->P->value('date_range_start') !== FALSE ? $this->P->value('date_range_start', 'ymd') : ''; $end_ymd = $this->P->value('date_range_end') !== FALSE ? $this->P->value('date_range_end', 'ymd') : ''; foreach ($occurrence_data[$data->default_data['entry_id']] as $times) { foreach ($times as $k => $odata) { $temp = new Calendar_event($odata, $start_ymd, $end_ymd); if (!empty($temp->dates)) { $temp->prepare_for_output(); $events[$odata['entry_id']] = $temp; $calendars[$events[$odata['entry_id']]->default_data['calendar_id']] = array(); } } } // ------------------------------------- // Fetch information about the calendars // ------------------------------------- $calendars = $this->data->fetch_calendar_data_by_id(array_keys($calendars)); // ------------------------------------- // Prep variable aliases // ------------------------------------- $variables = array('title' => 'occurrence_title', 'url_title' => 'occurrence_url_title', 'entry_id' => 'occurrence_id', 'author_id' => 'occurrence_author_id', 'author' => 'occurrence_author', 'status' => 'occurrence_status'); //custom variables with the letters 'url' are borked in //EE 2.6. Bug reported, but this should fix. //https://support.ellislab.com/bugs/detail/19337 if (version_compare($this->ee_version, '2.6.0', '>=')) { $variables['url_title'] = 'occurrence_borked_title'; ee()->TMPL->var_single['occurrence_borked_title'] = 'occurrence_borked_title'; unset(ee()->TMPL->var_single['occurrence_url_title']); ee()->TMPL->tagdata = str_replace(array(LD . 'occurrence_url_title' . RD, '"occurrence_url_title"', "'occurrence_url_title'"), array(LD . 'occurrence_borked_title' . RD, '"occurrence_borked_title"', "'occurrence_borked_title'"), ee()->TMPL->tagdata); } // ------------------------------------- // Add variables to the query result // ------------------------------------- foreach ($channel->query->result as $k => $row) { $channel->query->result[$k]['author'] = $row['screen_name'] != '' ? $row['screen_name'] : $row['username']; $entry_id = $row['entry_id']; if (isset($ids[0]) and $entry_id == $ids[0]) { $events[$entry_id] = $data; } elseif (!isset($events[$entry_id])) { unset($channel->query->result[$k]); continue; } // ------------------------------------- // Alias // ------------------------------------- foreach ($variables as $old => $new) { $channel->query->result[$k][$new] = $channel->query->result[$k][$old]; } // ------------------------------------- // Occurrence variables // ------------------------------------- foreach ($events[$entry_id]->default_data as $key => $val) { if (!is_array($val)) { if ($val == 'y' or $val == 'n') { $channel->query->result[$k]['occurrence_' . $key] = $val == 'y' ? TRUE : FALSE; } else { $channel->query->result[$k]['occurrence_' . $key] = $val; } } else { foreach ($val as $vkey => $vval) { if ($vval === 'y' or $vval === 'n') { $channel->query->result[$k]['occurrence_' . $key . '_' . $vkey] = $vval == 'y' ? TRUE : FALSE; } else { $channel->query->result[$k]['occurrence_' . $key . '_' . $vkey] = $vval; } } } } } unset($CDT); // ---------------------------------------- // Redeclare // ---------------------------------------- // We will reassign the $channel->query->result with our // reordered array of values. Thank you PHP for being so fast with array loops. // ---------------------------------------- $channel->query->result_array = $channel->query->result; // -------------------------------------------- // Typography // -------------------------------------------- ee()->load->library('typography'); ee()->typography->initialize(); ee()->typography->convert_curly = FALSE; $channel->fetch_categories(); // ------------------------------------- // Parse // ------------------------------------- //ee()->TMPL->log_item('Calendar: Parsing, via channel module'); $channel->parse_channel_entries(); // ------------------------------------- // Paginate // ------------------------------------- //$channel->add_pagination_data(); // ------------------------------------- // Related entries // ------------------------------------- if (version_compare($this->ee_version, '2.6.0', '<')) { if (count(ee()->TMPL->related_data) > 0 and count($channel->related_entries) > 0) { $channel->parse_related_entries(); } if (count(ee()->TMPL->reverse_related_data) > 0 and count($channel->reverse_related_entries) > 0) { $channel->parse_reverse_related_entries(); } } // ------------------------------------- // Send 'em home // ------------------------------------- $tagdata = $channel->return_data; // ------------------------------------- // put these back in case someone needs // them // ------------------------------------- // url title is manually parsed later // in the code here, so we don't // want to hose it // ------------------------------------- //custom variables with the letters 'url' are borked in //EE 2.6. Bug reported, but this should fix. //https://support.ellislab.com/bugs/detail/19337 if (version_compare($this->ee_version, '2.6.0', '>=')) { $tagdata = str_replace(array(LD . 'occurrence_borked_title' . RD, '"occurrence_borked_title"', "'occurrence_borked_title'"), array(LD . 'occurrence_url_title' . RD, '"occurrence_url_title"', "'occurrence_url_title'"), $tagdata); } // ------------------------------------- // Collect the tagdata // ------------------------------------- preg_match_all("/" . LD . 'occurrences id="(\\d+)"' . RD . '(.*?)' . LD . preg_quote(T_SLASH, '/') . 'occurrences' . RD . '/s', $tagdata, $matches); foreach ($matches[1] as $k => $id) { $tagdatas[$id] = $matches[2][$k]; } //ee()->TMPL = ee()->TMPL_orig; } // ------------------------------------- // Date and time variables // ------------------------------------- $dt_vars = array('start_date', 'end_date', 'start_time', 'end_time'); $count = 1; $total = 0; foreach ($data->dates as $date) { $total += count($date); } if (empty($data->dates)) { return $this->no_results(); } //-------------------------------------------- // reverse sorting //-------------------------------------------- if ($this->parent_method == 'occurrences' and ee()->TMPL->fetch_param('reverse') and strtolower(ee()->TMPL->fetch_param('reverse')) === 'true') { krsort($data->dates); } //-------------------------------------------- // orderby sorting //-------------------------------------------- /*if ($this->parent_method == 'occurrences' AND ee()->TMPL->fetch_param('orderby')) { $sort = (ee()->TMPL->fetch_param('sort') AND strtolower(ee()->TMPL->fetch_param('sort')) === 'DESC') ? 'DESC' : 'ASC'; }*/ //-------------------------------------------- // pagination //-------------------------------------------- if ($this->parent_method === 'occurrences') { $this->paginate = FALSE; } $limit = ee()->TMPL->fetch_param('occurrences_limit') ? ee()->TMPL->fetch_param('occurrences_limit') : $this->limit; if ($limit > 0 and $this->parent_method === 'occurrences' and $total > $limit) { //get pagination info $pagination_data = $this->universal_pagination(array('total_results' => $total, 'tagdata' => $tagdata . $this->paginate_tagpair_data, 'limit' => $limit, 'uri_string' => ee()->uri->uri_string, 'paginate_prefix' => 'calendar_')); //if we paginated, sort the data if ($pagination_data['paginate'] === TRUE) { $this->paginate = $pagination_data['paginate']; $this->page_next = $pagination_data['page_next']; $this->page_previous = $pagination_data['page_previous']; $this->p_page = $pagination_data['pagination_page']; $this->current_page = $pagination_data['current_page']; $this->pager = $pagination_data['pagination_links']; $this->basepath = $pagination_data['base_url']; $this->total_pages = $pagination_data['total_pages']; $this->paginate_data = $pagination_data['paginate_tagpair_data']; $this->page_count = $pagination_data['page_count']; //$tagdata = $pagination_data['tagdata']; } } //-------------------------------------------- // event limiter //-------------------------------------------- $offset = ee()->TMPL->fetch_param('occurrences_offset') ? ee()->TMPL->fetch_param('occurrences_offset') : 0; $page = ($this->current_page - 1) * $limit; if ($this->parent_method === 'occurrences' and $page > 0) { $offset += $page; } //-------------------------------------------- // Add final variables and swap out, // then add tagdata to return variable //-------------------------------------------- $offset_counter = 0; foreach ($data->dates as $ymd => $times) { foreach ($times as $time => $info) { //offset and limiting if ($this->parent_method === 'occurrences' and ++$offset_counter <= $offset) { continue; } if ($this->parent_method === 'occurrences' and $offset_counter > $limit + $offset) { break 2; } //-------------------------------------------- // output variables //-------------------------------------------- $tdata = isset($data->occurrences[$ymd][$time]['entry_id']) ? $tagdatas[$data->occurrences[$ymd][$time]['entry_id']] : $tagdatas[$data->default_data['entry_id']]; if ($info['all_day'] === TRUE or $info['all_day'] == 'y') { $info['date']['time'] = '0000'; $info['date']['hour'] = '00'; $info['date']['minute'] = '00'; $info['end_date']['time'] = '2400'; $info['end_date']['hour'] = '24'; $info['end_date']['minute'] = '00'; $info['duration']['hours'] = '24'; } $vars = array('single' => array('occurrence_duration_minutes' => $info['duration']['minutes'], 'occurrence_duration_hours' => $info['duration']['hours'], 'occurrence_duration_days' => $info['duration']['days'], 'occurrence_id' => isset($data->occurrences[$ymd][$time]['entry_id']) ? $data->occurrences[$ymd][$time]['entry_id'] : $data->default_data['entry_id'], 'occurrence_start_year' => $info['date']['year'], 'occurrence_start_month' => $info['date']['month'], 'occurrence_start_day' => $info['date']['day'], 'occurence_start_hour' => $info['date']['hour'], 'occurrence_start_minute' => $info['date']['minute'], 'occurrence_end_year' => $info['end_date']['year'], 'occurrence_end_month' => $info['end_date']['month'], 'occurrence_end_day' => $info['end_date']['day'], 'occurrence_end_hour' => $info['end_date']['hour'], 'occurrence_end_minute' => $info['end_date']['minute'], 'occurrence_count' => $count, 'occurrence_total' => $total, 'occurrence_author_id' => isset($entry_info['author_id']) ? $entry_info['author_id'] : '', 'occurrence_author' => isset($entry_info['screen_name']) ? $entry_info['screen_name'] : (isset($entry_info['username']) ? $entry_info['username'] : ''), 'occurrence_title' => isset($entry_info['title']) ? $entry_info['title'] : '', 'occurrence_url_title' => isset($entry_info['url_title']) ? $entry_info['url_title'] : '', 'occurrence_status' => isset($entry_info['status']) ? $entry_info['status'] : ''), 'conditional' => array('occurrence_all_day' => $info['all_day'], 'occurrence_multi_day' => $info['multi_day'], 'occurrence_status' => isset($entry_info['status']) ? $entry_info['status'] : '', 'occurrence_author_id' => isset($entry_info['author_id']) ? $entry_info['author_id'] : ''), 'date' => array('occurrence_start_date' => $info['date'], 'occurrence_start_time' => $info['date'], 'occurrence_end_date' => $info['end_date'], 'occurrence_end_time' => $info['end_date'])); $output .= $this->swap_vars($vars, $tdata); $count++; } } //-------------------------------------------- // offset too much? buh bye //-------------------------------------------- if (trim($output) === '') { return $this->no_results(); } return $output; }
/** * Edit Occurrences * * @access public * @param string * @return null */ public function edit_occurrences($message = '') { if ($message == '' and isset($_GET['msg'])) { $message = lang($_GET['msg']); } $this->cached_vars['message'] = $message; $this->cached_vars['module_menu_highlight'] = 'view_events'; // ------------------------------------- // Title and Crumbs // ------------------------------------- $this->add_crumb(lang('occurrences')); //must have an event_id if (ee()->input->get_post('event_id') === FALSE) { return FALSE; } // ------------------------------------- // filtering input data // ------------------------------------- $this->cached_vars['event_id'] = $event_id = ee()->input->get_post('event_id'); $this->cached_vars['status'] = $status = ee()->input->get_post('status') ? ee()->input->get_post('status') : ''; $this->cached_vars['date'] = $input_date = ee()->input->get_post('date') ? ee()->input->get_post('date') : ''; $this->cached_vars['direction'] = $direction = ee()->input->get_post('date_direction') ? ee()->input->get_post('date_direction') : ''; $this->cached_vars['orderby'] = $orderby = ee()->input->get_post('orderby') ? ee()->input->get_post('orderby') : 'start_date'; $this->cached_vars['sort'] = $sort = ee()->input->get_post('sort') ? ee()->input->get_post('sort') : 'ASC'; $this->cached_vars['offset'] = $offset = is_numeric(ee()->input->get_post('offset')) ? ee()->input->get_post('offset') : 0; $this->cached_vars['limit'] = $limit = ee()->input->get_post('limit') ? ee()->input->get_post('limit') : 50; $this->cached_vars['occurrences_limit'] = $occurrences_limit = ee()->input->get_post('occurrences_limit') ? ee()->input->get_post('occurrences_limit') : 100; //-------------------------------------------- // filtering options //-------------------------------------------- // date filtering if ($input_date) { $formatted_date = $this->data->format_input_date($input_date); $formatted_date = $formatted_date['ymd']; $dirs = array('greater' => '>=', 'less' => '<=', 'equal' => '='); $dir = ($direction and array_key_exists($direction, $dirs)) ? $dirs[$direction] : '='; } $this->cached_vars['statuses'] = $this->data->get_status_list(); $this->cached_vars['orderbys'] = array('title' => lang('event_title'), 'start_date' => lang('event_date'), 'status' => lang('status')); $this->cached_vars['sorts'] = array('ASC' => lang('ascending'), 'DESC' => lang('descending')); $this->cached_vars['limits'] = array('10' => '10', '50' => '50', '100' => '100', '250' => '250', '500' => '500'); $this->cached_vars['directions'] = array('greater' => lang('or_later'), 'less' => lang('or_earlier')); if ($this->cached_vars['date'] != '' and strpos($this->cached_vars['date'], '/') !== FALSE) { list($m, $d, $y) = explode('/', $this->cached_vars['date']); $this->cached_vars['range_date'] = array('year' => $y, 'month' => $m, 'day' => $d); } else { $this->cached_vars['range_date'] = array(); } $this->cached_vars['start_date'] = $this->cached_vars['direction'] != 'less' ? $this->cached_vars['range_date'] : array(); $this->cached_vars['end_date'] = $this->cached_vars['direction'] == 'less' ? $this->cached_vars['range_date'] : array(); //-------------------------------------------- // Get time format //-------------------------------------------- $this->cached_vars['clock_type'] = $clock_type = $this->data->preference('clock_type'); //-------------------------------------------- // event data //-------------------------------------------- $event_data = $this->data->fetch_all_event_data(array($event_id)); $events = array(); if (!class_exists('Calendar_event')) { require_once CALENDAR_PATH . 'calendar.event.php'; } $start_ymd = $input_date ? $formatted_date : (isset($this->P['date_range_start']->value->ymd) ? $this->P['date_range_start']->value->ymd : ''); $end_ymd = isset($this->P['date_range_end']->value->ymd) ? $this->P['date_range_end']->value->ymd : ''; foreach ($event_data as $k => $edata) { $temp = new Calendar_event($edata, $start_ymd, $end_ymd, $occurrences_limit); if (!empty($temp->dates)) { $temp->prepare_for_output(); $events[$edata['entry_id']] = $temp; } } //if this event isnt present, bail if (isset($events[$event_id]->default_data['entry_id']) === FALSE) { return FALSE; } //-------------------------------------------- // Occurrence data //-------------------------------------------- $entry_ids = array(); $entry_ids[] = $events[$event_id]->default_data['entry_id']; if (isset($events[$event_id]->occurrences) and !empty($events[$event_id]->occurrences)) { foreach ($events[$event_id]->occurrences as $ymd => $times) { foreach ($times as $time => $data) { if (!in_array($data['entry_id'], $entry_ids)) { $entry_ids[] = $data['entry_id']; } } } } $odata = $this->data->fetch_occurrence_channel_data($entry_ids); //-------------------------------------------- // vars //-------------------------------------------- if (!empty($events)) { $this->cached_vars['events'] = $events; $this->cached_vars['odata'] = $odata; $this->cached_vars[$this->sc->db->channel_id] = $channel_id = $odata[$events[$event_id]->default_data['entry_id']][$this->sc->db->channel_id]; $this->cached_vars['calendar_id'] = $calendar_id = $events[$event_id]->default_data['calendar_id']; $this->cached_vars['site_id'] = $site_id = $this->data->get_site_id(); $this->cached_vars['start_time'] = $start_time = $events[$event_id]->default_data['start_time']; $this->cached_vars['end_time'] = $end_time = $events[$event_id]->default_data['end_time']; $this->cached_vars['all_day'] = $all_day = $events[$event_id]->default_data['all_day'] === TRUE ? 'y' : 'n'; } //-------------------------------------------- // Sort by date //-------------------------------------------- if ($this->cached_vars['orderby'] == 'start_date') { foreach ($events as $id => $event) { if ($this->cached_vars['sort'] == 'DESC') { krsort($events[$id]->dates); } else { ksort($events[$id]->dates); } foreach ($event->dates as $date => $times) { if ($this->cached_vars['sort'] == 'DESC') { krsort($events[$id]->dates[$date]); } else { ksort($events[$id]->dates[$date]); } } } } //-------------------------------------------- // data and filtering //-------------------------------------------- $event_views = array(); $count = 0; foreach ($events[$event_id]->dates as $ymd => $times) { $this->CAL->CDT->change_ymd($ymd); //date filtering if ($input_date) { if ($dir == '>=' and $formatted_date > $ymd) { continue; } if ($dir == '<=' and $formatted_date < $ymd) { continue; } if ($dir == '=' and $formatted_date != $ymd) { continue; } } foreach ($times as $time => $data) { $event_view = array(); //-------------------------------------------- // status //-------------------------------------------- $event_view['ostatus'] = (isset($events[$event_id]->occurrences[$ymd][$time]) and isset($odata[$events[$event_id]->occurrences[$ymd][$time]['entry_id']]['status'])) ? $odata[$events[$event_id]->occurrences[$ymd][$time]['entry_id']]['status'] : $odata[$events[$event_id]->default_data['entry_id']]['status']; //-------------------------------------------- // status filter //-------------------------------------------- //if the input status is filtering, we need to skip if (!in_array(ee()->input->get_post('status'), array(FALSE, ''), TRUE) and $event_view['ostatus'] !== ee()->input->get_post('status')) { continue; } //-------------------------------------------- // title //-------------------------------------------- $event_view['title'] = isset($events[$event_id]->occurrences[$ymd][$time]) ? $odata[$events[$event_id]->occurrences[$ymd][$time]['entry_id']]['title'] : $odata[$events[$event_id]->default_data['entry_id']]['title']; //-------------------------------------------- // time range //-------------------------------------------- if ($data['all_day'] or $start_time == '0000' and $end_time == '2400') { $event_view['time_range'] = lang('all_day'); } else { $this->CAL->CDT->change_time(substr($time, 0, 2), substr($time, 2, 2)); $start = $clock_type == '12' ? $this->CAL->CDT->format_date_string('h:i a') : $this->CAL->CDT->format_date_string('H:i'); $this->CAL->CDT->change_time(substr($time, 4, 2), substr($time, 6, 2)); $end = $clock_type == '12' ? $this->CAL->CDT->format_date_string('h:i a') : $this->CAL->CDT->format_date_string('H:i'); $event_view['time_range'] = "{$start} – {$end}"; } //-------------------------------------------- // edit link //-------------------------------------------- $start_time = isset($data['start_time']) ? $data['start_time'] : $data['date']['time']; $end_time = isset($data['end_time']) ? $data['end_time'] : $data['end_date']['time']; $start_time = str_pad($start_time, 4, '0', STR_PAD_LEFT); $end_time = str_pad($end_time, 4, '0', STR_PAD_LEFT); $edit_link = BASE . AMP . "C=content_publish" . AMP . "M=entry_form" . AMP . "use_autosave=n"; if (isset($events[$event_id]->occurrences[$ymd][$time]) and isset($odata[$events[$event_id]->occurrences[$ymd][$time]['entry_id']]['entry_id']) and $odata[$events[$event_id]->occurrences[$ymd][$time]['entry_id']]['entry_id'] != $events[$event_id]->default_data['entry_id']) { $edit_link .= AMP . "{$this->sc->db->channel_id}={$channel_id}" . AMP . "entry_id={$events[$event_id]->occurrences[$ymd][$time]['entry_id']}" . AMP . "event_id={$events[$event_id]->default_data['event_id']}" . AMP . "occurrence_id={$events[$event_id]->occurrences[$ymd][$time]['occurrence_id']}" . AMP . "calendar_id={$calendar_id}" . AMP . "site_id={$site_id}" . AMP . "start_time={$start_time}" . AMP . "end_time={$end_time}" . AMP . "all_day={$events[$event_id]->occurrences[$ymd][$time]['all_day']}" . AMP . "ymd={$ymd}"; } else { $edit_link .= AMP . "entry_id={$events[$event_id]->default_data['entry_id']}" . AMP . "{$this->sc->db->channel_id}={$channel_id}" . AMP . "event_id={$events[$event_id]->default_data['event_id']}" . AMP . "calendar_id={$calendar_id}" . AMP . "site_id={$site_id}" . AMP . "start_time={$start_time}" . AMP . "end_time={$end_time}" . AMP . "all_day={$all_day}" . AMP . "ymd={$ymd}" . AMP . "start_date={$ymd}" . AMP . "end_date={$data['end_date']['ymd']}" . AMP . "new_occurrence=y"; } $event_view['edit_link'] = $edit_link; //-------------------------------------------- // time //-------------------------------------------- $event_view['time'] = $this->CAL->CDT->format_date_string($this->data->date_formats[$this->data->preference('date_format')]['cdt_format']); $event_view['count'] = ++$count; //add to output array $event_views[] = $event_view; } } $total = count($event_views); //-------------------------------------------- // Pagination //-------------------------------------------- ee()->load->library('pagination'); $config_base_url = $this->base . AMP . 'method=edit_occurrences' . AMP . 'limit=' . $this->cached_vars['limit'] . AMP . 'event_id=' . $event_id; //add filtering if present to base url if ($status) { $config_base_url .= AMP . 'status=' . $status; } if ($sort) { $config_base_url .= AMP . 'sort=' . $sort; } if ($limit) { $config_base_url .= AMP . 'limit=' . $limit; } if ($occurrences_limit) { $config_base_url .= AMP . 'occurrences_limit=' . $occurrences_limit; } if ($orderby) { $config_base_url .= AMP . 'orderby=' . $orderby; } if ($input_date) { $config_base_url .= AMP . 'date=' . $input_date; } if ($direction) { $config_base_url .= AMP . 'date_direction=' . $direction; } $config['base_url'] = $config_base_url; $config['total_rows'] = $total; $config['per_page'] = $limit; $config['page_query_string'] = TRUE; $config['query_string_segment'] = 'offset'; ee()->pagination->initialize($config); $this->cached_vars['paginate'] = ee()->pagination->create_links(); //-------------------------------------------- // clip if larger than limit //-------------------------------------------- // due to the way we are filtering, this is how // we have to limit our shown events instead of // limiting the queries. // The data is just too complex. //-------------------------------------------- if ($total > $limit) { $event_views = array_slice($event_views, $offset, $limit); } //-------------------------------------------- // now we can finally add to vars //-------------------------------------------- $this->cached_vars['event_views'] = $event_views; //-------------------------------------------- // output //-------------------------------------------- //need the jqui date picker for 2.x since we arent using our own jquidatepicker there ee()->cp->add_js_script(array('ui' => 'datepicker')); $this->cached_vars['form_url'] = $this->base . AMP . 'method=edit_occurrences' . AMP . 'event_id=' . $event_id; //-------------------------------------------- // Which View //-------------------------------------------- $this->cached_vars['current_page'] = $this->view('occurrences_edit.html', NULL, TRUE); //-------------------------------------------- // Load Homepage //-------------------------------------------- return $this->ee_cp_view('index.html'); }