From 3f38056d9de1d11f0e3fe0458348de67316142ac Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Mon, 1 Feb 2016 15:32:24 -0500 Subject: [PATCH] Clarify documentation and fix expectation when using current day in Tracker Submission Model API. --- .../models/base/SubmissionModelBase.php | 14 +++++---- .../tracker/models/pdo/SubmissionModel.php | 31 +++++++++---------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/modules/tracker/models/base/SubmissionModelBase.php b/modules/tracker/models/base/SubmissionModelBase.php index 17fcbaec6..c349b452d 100644 --- a/modules/tracker/models/base/SubmissionModelBase.php +++ b/modules/tracker/models/base/SubmissionModelBase.php @@ -92,13 +92,14 @@ abstract public function getSubmissionsByProducer($producerDao); abstract public function getScalars($submissionDao, $key = false); /** - * Get submissions associated with a given producer. + * Get the single latest submission associated with a given producer. * * @param Tracker_ProducerDao $producerDao producer DAO - * @param false | string $date the date in which to check + * @param false | string $date the latest time end the 24-hour interval or false to use the current day. * @param string $branch the branch of the submission for which to search - * @param bool $onlyOneDay whether to only get the last day. - * @return Tracker_SubmissionDao submission + * @param bool $onlyOneDay true to return submissions 24 hours back from $date, false otherwise. In the case of the + * of $date === false, $onlyOneDay will search only in the current day. + * @return false | Tracker_SubmissionDao submission */ abstract public function getLatestSubmissionByProducerDateAndBranch($producerDao, $date = false, @@ -107,9 +108,10 @@ abstract public function getLatestSubmissionByProducerDateAndBranch($producerDao /** * Get trends associated with a submission. + * * @param Tracker_SubmissionDao $submissionDao submission DAO - * @param bool $key whether to only retrieve key trends - * @return array trend DAOs + * @param bool $key true if only key trends should be returned, false otherwise. + * @return array Tracker_TrendDaos */ abstract public function getTrends($submissionDao, $key = true); } diff --git a/modules/tracker/models/pdo/SubmissionModel.php b/modules/tracker/models/pdo/SubmissionModel.php index 4715cda75..2f0a02752 100644 --- a/modules/tracker/models/pdo/SubmissionModel.php +++ b/modules/tracker/models/pdo/SubmissionModel.php @@ -154,13 +154,14 @@ public function getOrCreateSubmission($producerDao, $uuid) } /** - * Get submissions associated with a given producer. + * Get the single latest submission associated with a given producer. * * @param Tracker_ProducerDao $producerDao producer DAO - * @param false | string $date the date in which to check + * @param false | string $date the latest time end the 24-hour interval or false to use the current day. * @param string $branch the branch of the submission for which to search - * @param bool $onlyOneDay whether to only get the last day. - * @return Tracker_SubmissionDao submission | false + * @param bool $onlyOneDay true to return submissions 24 hours back from $date, false otherwise. In the case of the + * of $date === false, $onlyOneDay will search only in the current day. + * @return false | Tracker_SubmissionDao submission */ public function getLatestSubmissionByProducerDateAndBranch($producerDao, $date = false, $branch = 'master', $onlyOneDay = true) @@ -168,7 +169,7 @@ public function getLatestSubmissionByProducerDateAndBranch($producerDao, $date = if ($date) { $queryTime = date('Y-m-d H:i:s', strtotime($date)); } else { - $queryTime = date('Y-m-d H:i:s', time()); + $queryTime = date('Y-m-d', time()) . '23:59:59'; } $dayBeforeQueryTime = date('Y-m-d H:i:s', strtotime($queryTime) - self::SEC_IN_DAY); $sql = $this->database->select()->setIntegrityCheck(false) @@ -197,22 +198,20 @@ public function getLatestSubmissionByProducerDateAndBranch($producerDao, $date = /** * Get trends associated with a submission. + * * @param Tracker_SubmissionDao $submissionDao submission DAO - * @param bool $key whether to only retrieve key trends - * @return array trend DAOs + * @param bool $key true if only key trends should be returned, false otherwise. + * @return array Tracker_TrendDaos */ public function getTrends($submissionDao, $key = true) { + $sql = $this->database->select()->setIntegrityCheck(false)->from('tracker_trend')->join( + 'tracker_scalar', + 'tracker_scalar.trend_id = tracker_trend.trend_id', + array() + )->where('submission_id = ?', $submissionDao->getKey()); if ($key) { - $sql = $this->database->select()->setIntegrityCheck(false)->from('tracker_trend')->join( - 'tracker_scalar', - 'tracker_scalar.trend_id = tracker_trend.trend_id', - array() - )->where('submission_id = ?', $submissionDao->getKey() - )->where('key_metric = ?', 1); - } else { - $sql = $this->database->select()->setIntegrityCheck(false)->from('tracker_scalar') - ->where('submission_id = ?', $submissionDao->getKey()); + $sql = $sql->where('key_metric = ?', 1); } $trendDaos = array(); $rows = $this->database->fetchAll($sql);