From: Steve Sutton Date: Thu, 10 Mar 2016 19:28:58 +0000 (-0500) Subject: Getting the data into front end templates X-Git-Tag: v1.0.0^2~171 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=676d6d6fc0efec6b8bb4a11c72cf2ea672f24426;p=WP-Plugins%2Fglm-member-db-events.git Getting the data into front end templates Working with the Data Abstract event class --- diff --git a/classes/data/dataCategories.php b/classes/data/dataCategories.php index e7997f2..1680137 100644 --- a/classes/data/dataCategories.php +++ b/classes/data/dataCategories.php @@ -155,7 +155,7 @@ class GlmDataEventsCategories extends GlmDataAbstract } - /* + /** * Entry Post Processing Call-Back Method * * Perform post-processing for all result entries. @@ -331,7 +331,32 @@ class GlmDataEventsCategories extends GlmDataAbstract } - /* + /** + * getCategoriesWithCurrentEvents + * + * Returns a list of categories ordered by name that have an event with + * current event times. + * + * @access public + * @return void + */ + public function getCategoriesWithCurrentEvents() + { + $where = " T.id IN ( + SELECT category + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories + WHERE event IN ( + SELECT event + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times + WHERE active + AND start_time >= now() + ) + ) "; + $order = "T.name"; + return $this->getList($where, $order); + } + + /** * Check other requirements * * When deleteing categories, check for references in sub-categories and set them to no parent. @@ -358,7 +383,7 @@ class GlmDataEventsCategories extends GlmDataAbstract return $r; } - /* + /** * Sort a database result array (from DataAbstract.php) by parent, child relationships * * @param array $array Array to be sorted diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index c58c8d1..43346a3 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -79,6 +79,13 @@ class GlmDataEvents extends GlmDataAbstract * @access public */ public $MemberInfo; + /** + * postAddTimes + * + * @var bool + * @access public + */ + public $postAddTimes = false; /** * Constructor @@ -295,7 +302,7 @@ class GlmDataEvents extends GlmDataAbstract } - /* + /** * Entry Post Processing Call-Back Method * * Perform post-processing for all result entries. @@ -329,10 +336,28 @@ class GlmDataEvents extends GlmDataAbstract ;"; $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A); + if ($this->postAddTimes) { + $sql = " + SELECT ET.* + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET + WHERE ET.start_time >= now() + AND ET.active + AND ET.event = {$r['id']} + ORDER BY ET.start_time"; + $times = $this->wpdb->get_results($sql, ARRAY_A); + $r['times'] = $times; + // get the first element of times array + if ( !empty( $times ) ) { + $r['starting_date'] = $times[0]['start_time']; + $r['ending_date'] = $times[count($times) - 1]['end_time']; + } + } + + return $r; } - /* + /** * Update event slug - should be called after an event record is added or updated * * @param integer id ID of event that needs the slug updated @@ -362,7 +387,7 @@ class GlmDataEvents extends GlmDataAbstract } - /* + /** * Update timestamps for created, updated, approved * * @param string $field Field to update @@ -387,7 +412,7 @@ class GlmDataEvents extends GlmDataAbstract } - /* + /** * Delete an event and all data associated with it. * * @param integer $id ID of event @@ -433,6 +458,44 @@ class GlmDataEvents extends GlmDataAbstract } + /** + * getEventsByCategory + * + * Return array with a list of events by the category + * Option parameter to limit the results + * + * @param mixed $category Category to filter by + * @param bool $limit The limit of records to return + * + * @access public + * @return void + */ + public function getEventsByCategory( $category, $limit = null ) + { + $this->postAddTimes = true; + var_dump('hello there'); + $where = " + T.id IN ( + SELECT event + FROM " .GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "event_categories + WHERE category = {$category} + AND event IN ( + SELECT event + FROM " . GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX . "times AS ET + WHERE active + AND start_time >= now() + ) + ) + "; + $order = "T.id"; + if ($limit = filter_var($limit, FILTER_VALIDATE_INT)) { + $order .= " LIMIT {$limit} OFFSET 0"; + } + $events = $this->getList($where, $order); + + $this->postAddTimes = false; + return $events; + } } ?> diff --git a/models/front/events/baseAction.php b/models/front/events/baseAction.php index c9985bd..3be1e38 100644 --- a/models/front/events/baseAction.php +++ b/models/front/events/baseAction.php @@ -8,6 +8,8 @@ */ require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataEvents.php'; +require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataCategories.php'; +require_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataEventCategories.php'; /** * GlmMembersFront_events_list @@ -43,19 +45,19 @@ abstract class GlmMembersFront_events_baseAction extends GlmDataEvents public function getCategories() { - include GLM_MEMBERS_EVENTS_PLUGIN_PATH. '/models/front/events/testCategoryData.php'; - return $categories; + $categoryData = new GlmDataEventsCategories( $this->wpdb, $this->config ); + return $categoryData->getCategoriesWithCurrentEvents(); } - public function getModelEventsData($categoryId = null) + public function getModelEventsData($categoryId = null, $limit = null) { - include GLM_MEMBERS_EVENTS_PLUGIN_PATH. '/models/front/events/testEventsData.php'; + //echo '
categoryId: ' . print_r( $categoryId, true ) . '
'; + //echo '
limit: ' . print_r( $limit, true ) . '
'; if ($categoryId) { - return array_filter($events, function($data) use($categoryId) { - return ($data['category'] == $categoryId) ? 1 : 0; - }); + return $this->getEventsByCategory( $categoryId, $limit ); + } else { + return $this->getList(); } - return $events; } public function getModelEventData($eventId) diff --git a/models/front/events/list.php b/models/front/events/list.php index 3eb1df4..8a45bef 100644 --- a/models/front/events/list.php +++ b/models/front/events/list.php @@ -68,6 +68,7 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction } $categories = $this->getCategories(); + //echo '
' . print_r( $categories, true ) . '
'; wp_register_script( 'event-dashboard-js', GLM_MEMBERS_EVENTS_PLUGIN_BASE_URL . '/js/dashboard.js', @@ -83,16 +84,12 @@ class GlmMembersFront_events_list extends GlmMembersFront_events_baseAction $view = 'list.html'; break; default: - // for the dashboard need to get list of event categories and - // filter out the events - $events = $this->getModelEventsData(); $view = 'dashboard.html'; - foreach ( $categories as $cat ) { - $catEvents = array_filter( $events, function($data) use($cat) { - return ($data['category'] == $cat['id']) ? 1 : 0; - } ); + foreach ( $categories as $catid => $catData ) { + $catEvents = $this->getModelEventsData( $catid, 3 ); + //echo '
' . print_r( $catEvents, true ) . '
'; if ( !empty($catEvents) ) { - $categoryEvents[$cat['id']] = $catEvents; + $categoryEvents[$catid] = $catEvents; } } break; diff --git a/setup/frontHooks.php b/setup/frontHooks.php index f6ca254..d51f93d 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -33,7 +33,7 @@ add_filter('rewrite_rules_array', function($rules) { return $newrules + $rules; }); -// Add memberslug query var +// Add eventId query var add_filter('query_vars', function($vars) { array_push($vars, 'eventId'); return $vars; diff --git a/views/front/events/dashboard.html b/views/front/events/dashboard.html index f0cc0dd..440f90d 100644 --- a/views/front/events/dashboard.html +++ b/views/front/events/dashboard.html @@ -20,8 +20,9 @@ {break} {/if}
  • + {$event.starting_date|date_format}
    - {$event.title} + {$event.name}
  • {/foreach}