From: Chuck Scott Date: Tue, 19 Apr 2016 19:49:12 +0000 (-0400) Subject: Fixed ref_dest confusion. X-Git-Tag: v1.0.0^2~98 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=7702f3a3b5b26b2f4f813a97db8888e4fd4e815f;p=WP-Plugins%2Fglm-member-db-events.git Fixed ref_dest confusion. --- diff --git a/classes/data/dataEvents.php b/classes/data/dataEvents.php index 14cdf15..8d5be8c 100644 --- a/classes/data/dataEvents.php +++ b/classes/data/dataEvents.php @@ -89,6 +89,8 @@ class GlmDataEvents extends GlmDataAbstract public $postAddLocations = false; public $postAddRecurrences = false; public $dateRange = "start_time >= now()"; + public $postFirstAndLastTimes = false; + public $postCategories = true; /** * Constructor @@ -192,13 +194,6 @@ class GlmDataEvents extends GlmDataAbstract 'use' => 'lged' ), - // Reference Target - Insert new record and for recall - 'ref_dest' => array ( - 'field' => 'ref_dest', - 'type' => 'integer', - 'use' => 'ilged' - ), - // Ref_name (member name - need to update this to be Reference Type aware) 'ref_dest' => array ( 'field' => 'ref_dest', @@ -210,15 +205,12 @@ class GlmDataEvents extends GlmDataAbstract 'use' => 'a' ), - // Member Name (need to update this to be Reference Type aware - 'ref_name' => array( + // Reference Target ID + 'ref_dest_id' => array ( 'field' => 'ref_dest', - 'as' => 'ref_name', - 'type' => 'pointer', - 'p_table' => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', - 'p_field' => 'name', - 'p_static' => true, - 'use' => '' + 'as' => 'ref_dest_id', + 'type' => 'integer', + 'use' => 'ilged' ), // Hide Address flag @@ -479,21 +471,23 @@ class GlmDataEvents extends GlmDataAbstract { // Get Member Category data for this entry - $sql = " - SELECT EC.event AS event_id, C.id, C.name, C.descr, - COALESCE ( - ( - SELECT name - FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "categories - WHERE id = C.parent - ), '' - ) AS parent_name - FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "categories AS C, - ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "event_categories AS EC - WHERE C.id = EC.category - AND EC.event = ".$r['id']." - ;"; - $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A); + if ($this->postCategories) { + $sql = " + SELECT EC.event AS event_id, C.id, C.name, C.descr, + COALESCE ( + ( + SELECT name + FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "categories + WHERE id = C.parent + ), '' + ) AS parent_name + FROM ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "categories AS C, + ".GLM_MEMBERS_EVENTS_PLUGIN_DB_PREFIX. "event_categories AS EC + WHERE C.id = EC.category + AND EC.event = ".$r['id']." + ;"; + $r['categories'] = $this->wpdb->get_results($sql, ARRAY_A); + } if ($this->postAddTimes) { include_once GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH . '/data/dataTimes.php'; @@ -540,6 +534,13 @@ class GlmDataEvents extends GlmDataAbstract } + // if List, Get, or Update, and if requested, get the first and last occurances for this event + if ($this->postFirstAndLastTimes && in_array($a, array('l', 'g', 'u')) ) { + $firstLast = $this->getFirstAndLastTimes($r['id']); + $r['firstDate'] = $firstLast['first']; + $r['lastDate'] = $firstLast['last']; + } + return $r; } @@ -748,6 +749,60 @@ class GlmDataEvents extends GlmDataAbstract $this->postAddTimes = false; return $events; } + + + /** + * Get first and last date/time for an event + * + * @param integer $id ID of event + * + * @return array ('first' => {datetime data}, 'last' => {datetime data}) + */ + public function getFirstAndLastTimes($id = false) + { + + // Load the data class for Event Times + require_once(GLM_MEMBERS_EVENTS_PLUGIN_CLASS_PATH.'/data/dataTimes.php'); + $Times = new GlmDataEventsTimes($this->wpdb, $this->config); + + // Select the first and last entries by matching min and max start times + $first = $Times->getEntry(0, 'id', "T.event = $id ORDER BY T.start_time"); + $last = $Times->getEntry(0, 'id', "T.event = $id ORDER BY T.start_time DESC"); + + $r = array('first' => date('m/d/Y', $first['start_time']['timestamp']), 'last' => date('m/d/Y', $last['start_time']['timestamp'])); + + return $r; + + } + + /** + * Get ID/Name list + * + * @param string $where + * + * @return array ID/Name pairs + */ + public function getIdName($where = 'true') + { + $savedFields = $this->fields; + $savedCategories = $this->postCategories; + + $this->postCategories = false; + + $this->fields = array( + 'id' => $savedFields['id'], + 'name' => $savedFields['name'] + ); + + $r = $this->getList($where); + + $this->fields = $savedFields; + $this->postCategories = $savedCategories; + + return $r; + + } + } ?>