* @license GPL-2.0+ * @link https://arlo.co * @copyright 2018 Arlo */ require_once 'class-arlo-for-wordpress-lists.php'; class Arlo_For_Wordpress_Events extends Arlo_For_Wordpress_Lists { const TABLENAME = 'arlo_events'; public function __construct() { $this->singular = __( 'Event', 'arlo-for-wordpress' ); $this->plural = __( 'Events', 'arlo-for-wordpress' ); parent::__construct(); } public function get_title() { $title = parent::get_title(); $et_id = filter_input(INPUT_GET, 'et_id', FILTER_SANITIZE_STRING); if (!empty($et_id) && !empty(self::$filter_column_mapping['et_id']) && intval($et_id > 0) && !empty($this->items[0]->et_name)) { $title .= ' for template: ' . $this->items[0]->et_name; } return $title; } public function set_table_name() { $this->table_name = $this->wpdb->prefix . self::TABLENAME . ' AS e'; } public function get_columns() { return $columns = [ 'e_code' => __( 'Code', 'arlo-for-wordpress' ), 'e_name' => __( 'Name', 'arlo-for-wordpress' ), 'e_startdatetime' => __( 'Start date', 'arlo-for-wordpress' ), 'e_finishdatetime' => __( 'Finish date', 'arlo-for-wordpress' ), 'v_name' => __( 'Venue name', 'arlo-for-wordpress' ), 'et_descriptionsummary' => __( 'Summary', 'arlo-for-wordpress' ), 'e_sessiondescription' => __( 'Description', 'arlo-for-wordpress' ), 'e_notice' => __( 'Notice', 'arlo-for-wordpress' ), 'e_session_num' => __( 'Num. of sessions', 'arlo-for-wordpress' ), 'e_region' => __( 'Regions', 'arlo-for-wordpress' ), //'e_isonline' => __( 'Online', 'arlo-for-wordpress' ), ]; } public function get_hidden_columns() { return array(); } public function get_sortable_columns() { return array( 'e_code' => array( 'e_code', true ), 'e_name' => array( 'e_name', true ), 'e_startdatetime' => array( 'e_startdatetime', true ), 'e_finishdatetime' => array( 'e_finishdatetime', true ), 'v_name' => array( 'v_name', true ), 'e_placesremaining' => array( 'e_placesremaining', true ), 'et_descriptionsummary' => array( 'et_descriptionsummary', true ), 'e_sessiondescription' => array( 'e_sessiondescription', true ), ); } public function column_default($item, $column_name) { switch ($column_name) { case 'e_code': case 'e_placesremaining': case 'e_region': return esc_html($item->$column_name); case 'e_name': $field = '
' . esc_html($item->e_name) . (is_numeric($item->e_placesremaining) && $item->e_placesremaining > 0 ? ' (' . $item->e_placesremaining . ')' : '') . '
'; if ($item->e_isonline) { $field .= '
Live online
'; } if (!empty($item->presenters)) $field .= '
' . esc_html($item->presenters) . ''; if (!empty($item->e_providerorganisation)) { $field .= '
'; if (!empty($item->e_providerwebsite)) { $field .= '' . esc_html($item->$column_name) . ''; } else { $field .= esc_html($item->e_providerorganisation); } $field .= "
"; } if (!empty($item->e_registeruri)) $field .= '
' . strip_tags($item->e_registermessage) . '
'; return $field; case 'et_descriptionsummary': case 'e_sessiondescription': if (!empty($item->$column_name)) return '
' . strip_tags($item->$column_name) . '
'; break; case 'e_startdatetime': case 'e_finishdatetime': //convert to the given timezone, if available if (!empty($this->timezones[$item->e_timezone_id])) { $timewithtz = str_replace(' ', 'T', $item->$column_name) . $item->e_datetimeoffset; $date = new \DateTime($timewithtz); $timezone = new \DateTimeZone(\Arlo\Arrays::$arlo_timezone_system_names_to_php_tz_identifiers[$this->timezones[$item->e_timezone_id]['windows_tz_id']]); if ($timezone != null) { $date->setTimezone($timezone); return strftime("%Y-%m-%d %H:%M:%S", $date->getTimestamp() + $date->getOffset()) . " " . $date->format("T"); } } return esc_html($item->$column_name) . " " . esc_html($item->e_timezone); break; case 'v_name': $field = ''; if (!empty($item->$column_name)) { $field = '
' . esc_html($item->$column_name). '
'; } if (!empty($item->e_locationname)) { $field .= '
' . esc_html($item->e_locationname) . (!empty($item->e_locationroomname) ? ' (' . esc_html($item->e_locationroomname) . ')' : '') . '
'; } elseif (!empty($item->e_locationroomname)) { $field .= '
' . esc_html($item->e_locationroomname) . '
'; } return $field; case 'e_session_num': if (!empty($item->$column_name)) return '' . esc_html($item->$column_name) . ''; break; default: return ''; } } function column_e_code($item) { $actions = array( 'edit' => sprintf('Edit', esc_attr($this->platform_url), $item->e_arlo_id), 'view' => sprintf('View', $item->guid), ); return sprintf('%1$s %2$s', esc_html($item->e_code), $this->row_actions($actions) ); } protected function get_sql_where_array() { return [ "e.import_id = " . $this->import_id, "e.e_parent_arlo_id = 0" ]; } protected function get_searchable_fields() { return [ 'e_code', 'e_name', 'v_name', 'e_locationname', 'e_locationroomname', 'et_descriptionsummary', 'e_sessiondescription', 'e_notice', 'e_registermessage', 'e_providerorganisation', ]; } public function get_sql_query() { $where = $this->get_sql_where_expression(); return " SELECT e.e_arlo_id, e.e_code, e.e_name, e.e_startdatetime, e.e_finishdatetime, e.e_datetimeoffset, e.e_timezone, e.e_timezone_id, v.v_name, e.e_locationname, e.e_locationroomname, e.e_isfull, e.e_placesremaining, e.e_sessiondescription, e.e_notice, e.e_registermessage, e.e_registeruri, e.e_providerorganisation, e.e_providerwebsite, e.e_isonline, (SELECT GROUP_CONCAT(e_region) FROM " . $this->wpdb->prefix . "arlo_events WHERE e_arlo_id = e.e_arlo_id AND import_id = " . $this->import_id . " AND e.import_id = " . $this->import_id . " GROUP BY e_arlo_id) AS e_region, et.et_name, et.et_descriptionsummary, (SELECT COUNT(1) FROM " . $this->wpdb->prefix . "arlo_events WHERE e_parent_arlo_id = e.e_arlo_id AND e_region = e.e_region) as e_session_num, GROUP_CONCAT(DISTINCT CONCAT_WS(' ', p.p_firstname, p.p_lastname) ORDER BY ep.p_order, p.p_firstname SEPARATOR ', ') AS presenters, posts.guid FROM " . $this->table_name . " LEFT JOIN " . $this->wpdb->prefix . "arlo_eventtemplates AS et USING (et_arlo_id) LEFT JOIN " . $this->wpdb->prefix . "arlo_events_presenters AS ep ON e.e_id = ep.e_id LEFT JOIN " . $this->wpdb->prefix . "arlo_presenters AS p USING (p_arlo_id) LEFT JOIN " . $this->wpdb->prefix . "arlo_venues AS v ON e.v_id = v.v_arlo_id LEFT JOIN " . $this->wpdb->prefix . "posts AS posts ON et.et_post_id = posts.ID WHERE " . $where . " GROUP BY e.e_arlo_id "; } public function get_new_link() { return esc_url(sprintf('https://%s/management/Console/#/events/new/', $this->platform_url)); } public function get_list_link() { return esc_url(sprintf('https://%s/management/Courses/Courses2.aspx', esc_attr($this->platform_url))); } }