/** * Return the first instance of a property of this name */ function GetProperty($type) { foreach ($this->properties as $k => $v) { if (is_object($v) && $v->Name() == $type) { return $v; } else { if (!is_object($v)) { debug_error_log("ERROR", 'vComponent::GetProperty(): Trying to get %s on %s which is not an object!', $type, $v); } } } /** So we can call methods on the result of this, make sure we always return a vProperty of some kind */ return null; }
function definition() { require_js_files(); $mform =& $this->_form; $page = $this->_customdata['page']; $workflow = $page->workflow; $data = $workflow->unserialize_data(); // Configure the schedule display $schedule_string = ''; $once = '1'; // Replace timezone with proper text $tz = $data['timezone']; $timezone = usertimezone($tz); debug_error_log("/local/elisreports/form/scheduling.php::scheduling_form_step_confirm::definition() enddate = {$data['schedule']['enddate']}, timezone = {$tz} ({$timezone})"); // Set up for simple recurrence if ($data['recurrencetype'] == scheduling_workflow::RECURRENCE_SIMPLE) { if ($data['schedule']['runsremaining'] == '' && $data['schedule']['enddate'] == '') { $schedule_string = get_string('indefinitely', 'local_elisreports'); } elseif ($data['schedule']['enddate'] != '') { $enddate = userdate($data['schedule']['enddate'] + DAYSECS - 1, '', $tz); // 2nd param to userdate() was: get_string('strftimedaydate') $schedule_string = get_string('simple_until', 'local_elisreports', $enddate); } else { // Frequency schedule $a = new stdClass(); $a->num = $data['schedule']['runsremaining']; $a->freq = $data['schedule']['frequency']; $a->freqtype = $data['schedule']['frequencytype']; $schedule_string = get_string('simple_freq', 'local_elisreports', $a); } } else { // calendar schedule $min = str_pad($data['schedule']['minute'], 2, '0', STR_PAD_LEFT); $hour = $data['schedule']['hour']; $schedule_string .= get_string('at_time', 'local_elisreports', "{$hour}:{$min} ({$timezone})"); // days if ($data['schedule']['dayofweek'] == '*' && $data['schedule']['day'] == '*') { $schedule_string .= get_string('every_day', 'local_elisreports'); } elseif ($data['schedule']['day'] == '*') { //Weekdays specified $days_array = array('1' => get_string('mon', 'calendar'), '2' => get_string('tue', 'calendar'), '3' => get_string('wed', 'calendar'), '4' => get_string('thu', 'calendar'), '5' => get_string('fri', 'calendar'), '6' => get_string('sat', 'calendar'), '7' => get_string('sun', 'calendar')); $days_selected_array = explode(',', $data['schedule']['dayofweek']); $days_string = ''; $count = 0; foreach ($days_selected_array as $weekday) { if ($count > 0) { $days_string .= ', '; } $days_string .= $days_array[$weekday]; $count++; } //Replace last , with the word and $days_string = strrev(preg_replace('/,/', strrev(get_string('and', 'local_elisreports')), strrev($days_string), $once)); $schedule_string .= get_string('on_days', 'local_elisreports', $days_string); } else { //Specific days of the month $days_string = strrev(preg_replace('/,/', strrev(get_string('and', 'local_elisreports')), strrev($data['schedule']['day']), $once)); $schedule_string .= get_string('month_days', 'local_elisreports', $days_string); } // months if ($data['schedule']['month'] == '1,2,3,4,5,6,7,8,9,10,11,12' || $data['schedule']['month'] == '*') { $months_string = get_string('every_month', 'local_elisreports'); $data['schedule']['month'] = '1,2,3,4,5,6,7,8,9,10,11,12'; } else { $months_array = array('1' => strftime('%b', mktime(0, 0, 0, 1, 1)), '2' => strftime('%b', mktime(0, 0, 0, 2, 1)), '3' => strftime('%b', mktime(0, 0, 0, 3, 1)), '4' => strftime('%b', mktime(0, 0, 0, 4, 1)), '5' => strftime('%b', mktime(0, 0, 0, 5, 1)), '6' => strftime('%b', mktime(0, 0, 0, 6, 1)), '7' => strftime('%b', mktime(0, 0, 0, 7, 1)), '8' => strftime('%b', mktime(0, 0, 0, 8, 1)), '9' => strftime('%b', mktime(0, 0, 0, 9, 1)), '10' => strftime('%b', mktime(0, 0, 0, 10, 1)), '11' => strftime('%b', mktime(0, 0, 0, 11, 1)), '12' => strftime('%b', mktime(0, 0, 0, 12, 1))); $months_selected_array = explode(',', $data['schedule']['month']); $months_string = ''; $count = 0; foreach ($months_selected_array as $month) { if ($count > 0) { $months_string .= ', '; } $months_string .= $months_array[$month]; $count++; } //Replace last , with the word and $months_string = strrev(preg_replace('/,/', strrev(get_string('and', 'local_elisreports')), strrev($months_string), $once)); } $schedule_string .= get_string('for_month', 'local_elisreports', $months_string); //Include end date if selected if (isset($data['schedule']['enddate']) && $data['schedule']['enddate'] != '') { $schedule_string .= get_string('until_date', 'local_elisreports', userdate($data['schedule']['enddate'] + DAYSECS - 1, '', $tz)); // '' was: get_string('strftimedaydate') } else { $schedule_string .= get_string('until_indefinitely', 'local_elisreports'); } } // Create the param_string for selected parameters and their values $param_string = ''; if (isset($this->_customdata['filterobject']) && isset($data['parameters'])) { $report = $page->workflow->get_report_instance(); // Configure the parameter display $parameters = $data['parameters']; // Use this object to set up our parameter setting $filter_object = $this->_customdata['filterobject']; $filter_object_fields = $filter_object->_fields; // Merge in any secondary filterings here... if (isset($this->_customdata['filterobject']->secondary_filterings)) { foreach ($filter_object->secondary_filterings as $key => $secondary_filtering) { $filter_object_fields = array_merge($filter_object_fields, $secondary_filtering->_fields); } } if (!empty($filter_object_fields)) { $fields = $filter_object_fields; // Create empty filtering array to be used following... $filtering_array = array(); foreach ($parameters as $pname => $pvalue) { if (strpos($pname, '_') !== FALSE) { //multi-element group $parts = explode('_', $pname); $group_name = $parts[0]; } else { $group_name = ''; } if (isset($fields[$pname])) { $sub_data = $fields[$pname]->check_data($parameters); if ($sub_data === false) { continue; // nothing new } } elseif (isset($fields[$group_name])) { $sub_data = $fields[$group_name]->check_data($parameters); if ($sub_data === false) { continue; // nothing new } $pname = $group_name; } else { continue; } //update filter object with check_data contents if (!isset($filtering_array[$pname])) { $filtering_array[$pname][] = $sub_data; } } //Now get the description etc. $count = 0; foreach ($filtering_array as $fname => $datas) { if (!array_key_exists($fname, $filter_object_fields)) { continue; // filter not used } $field = $fields[$fname]; foreach ($datas as $i => $sub_data) { $description = $field->get_label($sub_data); if ($count > 0) { $param_string .= '<br>'; } $param_string .= $description; $count++; } } } } if (isset($this->_customdata['secondary_filterings'])) { // Use this object to set up our parameter setting $filter_object = $this->_customdata['secondary_filterings']; //add additional data from secondary filters foreach ($filter_object as $secondary_filtering) { //recurse for this filter $temp_result = php_report_filtering_get_per_filter_data($secondary_filtering, $form_data); //merge data into result if (!empty($temp_result)) { foreach ($temp_result as $key => $value) { //each filter should have only been shown once (see form for details) if (!isset($per_filter_data[$key])) { $per_filter_data[$key] = $value; } } } } } if ($param_string == '') { //report does not use filters $param_string = get_string('label_no_parameters', 'local_elisreports'); } // Set proper date display or NA for end date if (isset($data['schedule']['enddate']) && $data['schedule']['enddate'] != null) { $enddate = userdate($data['schedule']['enddate'], get_string('strftimedaydate'), $tz); } else { $enddate = get_string('na', 'local_elisreports'); } $mform->addElement('hidden', '_wfid', $workflow->id); $mform->setType('_wfid', PARAM_INT); $mform->addElement('static', 'label', get_string('label', 'local_elisreports') . ':', htmlspecialchars($data['label'])); $mform->addElement('static', 'description', get_string('description') . ':', htmlspecialchars($data['description'])); $mform->addElement('static', 'timezone', get_string('timezone') . ':', $timezone); $mform->addElement('static', 'startdate', get_string('startdate', 'local_elisreports') . ':', userdate($data['startdate'], get_string('strftimedaydate'), $tz)); $mform->addElement('static', 'enddate', get_string('enddate', 'local_elisreports') . ':', $enddate); $mform->addElement('static', 'recurrencetype', get_string('recurrencetype', 'local_elisreports') . ':', htmlspecialchars($data['recurrencetype'])); $mform->addElement('static', 'schedule', get_string('schedule') . ':', $schedule_string); $mform->addElement('static', 'parameters', get_string('parameters', 'local_elisreports') . ':', $param_string); $mform->addElement('static', 'format', get_string('format') . ':', get_string($data['format'], 'local_elisreports')); $mform->addElement('static', 'recipients', get_string('recipientslist') . ':', htmlspecialchars($data['recipients'])); $mform->addElement('static', 'message', get_string('message', 'message') . ':', $data['message']); workflowpage::add_navigation_buttons($mform, scheduling_workflow::STEP_RECIPIENTS, workflow::STEP_FINISH); }
public function get_submitted_values_for_step_schedule() { $form = new scheduling_form_step_schedule(null, $this); $data = $form->get_data(false); // set the startdate to today if set to start now if (!isset($data->starttype) || $data->starttype == 0) { $data->startdate = time(); } else { $data->startdate = to_gmt($data->startdate, $data->timezone); } debug_error_log("get_submitted_values_for_step_schedule(): startdate = {$data->startdate}"); // Process simple calendar workflow if ($data->recurrencetype != scheduling_workflow::RECURRENCE_CALENDAR) { if (!isset($data->runtype) || $data->runtype == 0) { $data->enddate = null; $data->runsremaining = null; } elseif ($data->runtype == 1) { $data->runsremaining = null; debug_error_log("get_submitted_values_for_step_schedule(): adjusting enddate from {$data->enddate} to " . to_gmt($data->enddate, $data->timezone)); $data->enddate = to_gmt($data->enddate, $data->timezone); } else { $data->enddate = null; } } else { if ($data->calenddate) { debug_error_log("get_submitted_values_for_step_schedule(): adjusting calenddate from {$data->calenddate} to " . to_gmt($data->calenddate, $data->timezone)); $data->calenddate = to_gmt($data->calenddate, $data->timezone); $data->enddate = $data->calenddate; } else { $data->enddate = null; } $data->time = isset($data->time) ? $data->time : 0; //debug_error_log("get_submitted_values_for_step_schedule(): data->time = {$data->time}"); $data->hour = floor($data->time / HOURSECS) % 24; $data->minute = floor($data->time / MINSECS) % MINSECS; if (!isset($data->caldaystype) || $data->caldaystype == 0) { $data->dayofweek = '*'; $data->day = '*'; } elseif ($data->caldaystype == 1) { $dayofweek = empty($data->dayofweek) ? array() : $data->dayofweek; $data->dayofweek = array(); foreach ($dayofweek as $day => $dummy) { $data->dayofweek[] = $day; } $data->dayofweek = implode(',', $data->dayofweek); $data->day = '*'; } elseif ($data->caldaystype == 2) { $data->dayofweek = '*'; $days = explode(',', $data->monthdays); $data->day = array(); foreach ($days as $day) { if ((int) $day) { $data->day[] = (int) $day; } } $data->day = implode(',', $data->day); } $months = empty($data->month) ? array() : $data->month; $data->month = array(); foreach ($months as $month => $dummy) { $data->month[] = $month; } $data->month = implode(',', $data->month); } return $data; }