/** Intervals' list HTML table by activity */ function pacwtt_interval_table($activity_id) { // Database Models $pacwtt_model_interval = new PACWTT_Model_Interval(); $results = $pacwtt_model_interval->get_activity_items($activity_id); // Table Headers $html_table = '<table id="pacwtt-intervals-table" class="widefat fixed"><thead><tr>'; $html_table .= '<th>' . __('Day of the week', 'pacwtt-plugin') . '</th>'; $html_table .= '<th>' . __('Start', 'pacwtt-plugin') . '</th>'; $html_table .= '<th>' . __('Finish', 'pacwtt-plugin') . '</th>'; $html_table .= '<th>' . __('Description', 'pacwtt-plugin') . '</th>'; $html_table .= '<th>' . __('Operations', 'pacwtt-plugin') . '</th>'; $html_table .= '</tr></thead><tbody>'; // Table Data if (count($results) > 0) { foreach ($results as $interval) { $html_table .= '<tr>'; $html_table .= '<td>' . $pacwtt_model_interval->dow_map[$interval['weekday']] . '</td>'; $html_table .= '<td>' . esc_html($interval['time_start']) . '</td>'; $html_table .= '<td>' . esc_html($interval['time_end']) . '</td>'; $html_table .= '<td>' . esc_html($interval['description']) . '</td>'; $html_table .= '<td><a id="' . $interval['id'] . '" class="pacwtt-interval-delete-link" href="javascript:void(0)">' . __('Delete', 'pacwtt-plugin') . '</a></td>'; $html_table .= '</tr>'; } } else { $html_table .= "<tr><td align='center' colspan ='5'>" . __('No results found.', 'pacwtt-plugin') . "</td></tr>"; } $html_table .= '</tbody></table>'; return $html_table; }
function pacwtt_shortcode_handler($atts, $content = null) { // Database Models $pacwtt_model_activity = new PACWTT_Model_activity(); $pacwtt_model_interval = new PACWTT_Model_Interval(); $days_sequence = ''; if (!isset($atts['id'])) { // Insufficient parameters return '<b>' . __("Error: no activity's id specified.", 'pacwtt-plugin') . '</b>'; } //Attributes default $attributes_default = array('id' => '', 'layout' => get_option('pacwtt_option_layout'), 'dnsize' => 'full'); $options = shortcode_atts($attributes_default, $atts); // "id" parameter validation and fetch $activity_data = $pacwtt_model_activity->read_item($options['id']); if (NULL === $activity_data) { // Non existent 'id' activity return '<b>' . __("Error: requested id not found.", 'pacwtt-plugin') . '</b>'; } $interval_data = $pacwtt_model_interval->get_activity_items($options['id'], false); // "size" parameter validation $days_sequence = $pacwtt_model_interval->dow_map; switch ($options['dnsize']) { case 'three': $days_sequence = array_map('shortcode_dnsize_three', $days_sequence); break; case 'full': // Do nothing break; default: // Invalid scortcode parameter return '<b>' . sprintf(__("Error: dnsize=%s parameter value not allowed.", 'pacwtt-plugin'), $options['dnsize']) . '</b>'; } $days_sequence = array_flip($days_sequence); // day_name => day_index // "week starts on monday" global option if ('on' == get_option('pacwtt_option_monday')) { $options['monday'] = true; } else { $options['monday'] = false; } if ($options['monday'] == false) { // sunday // nothing to do } elseif ($options['monday'] == true) { // Monday first (rotate left) $days_sequence = array_assoc_rol($days_sequence); } else { // Should not be executed return '<b>' . __("Error: global option 'monday' value not valid.", 'pacwtt-plugin') . '</b>'; } // Layout parameter validation if ('text' != $options['layout'] && 'time_boxes' != $options['layout']) { // Invalid scortcode parametr return '<b>' . sprintf(__("Error: layout=%s parameter value not allowed.", 'pacwtt-plugin'), $options['layout']) . '</b>'; } switch ($options['layout']) { case 'text': $html_output = pacwtt_shortcode_text($options['id'], $interval_data, $days_sequence); break; case 'time_boxes': $html_output = pacwtt_shortcode_time_boxes($options['id'], $interval_data, $days_sequence); break; default: wp_die(sprintf(__('Fatal Error: layout=%s parameter value not allowed.', 'pacwtt-plugin'), $options['layout'])); } //Output wp_enqueue_style('pacwtt-css-tables'); return $html_output; }