Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Commit

Permalink
Improved code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Olde Hampsink committed Feb 24, 2016
1 parent 1630dd5 commit e24163d
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions elementtypes/AuditLogElementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,6 @@ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $crit
$query->andWhere(DbHelper::parseParam('auditlog.origin', $criteria->origin, $query->params));
}

// Check for date modified
if (!empty($criteria->modified)) {
$query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', $criteria->modified, $query->params));
}

// Check before
if (!empty($criteria->before)) {
$query->andWhere(DbHelper::parseParam('auditlog.before', $criteria->before, $query->params));
Expand All @@ -213,6 +208,31 @@ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $crit
$query->andWhere(DbHelper::parseParam('auditlog.after', $criteria->after, $query->params));
}

// Check for status
if (!empty($criteria->status)) {
$query->andWhere(DbHelper::parseParam('auditlog.status', $criteria->status, $query->params));
}

// Dates
$this->applyDateCriteria($criteria, $query);

// Search
$this->applySearchCriteria($criteria, $query);
}

/**
* Apply date criteria.
*
* @param ElementCriteriaModel $search
* @param DbCommand $query
*/
private function applyDateCriteria(ElementCriteriaModel $criteria, DbCommand $query)
{
// Check for date modified
if (!empty($criteria->modified)) {
$query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', $criteria->modified, $query->params));
}

// Check for date from
if (!empty($criteria->from)) {
$query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', '>= '.DateTimeHelper::formatTimeForDb($criteria->from), $query->params));
Expand All @@ -223,18 +243,16 @@ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $crit
$criteria->to->add(new DateInterval('PT23H59M59S'));
$query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', '<= '.DateTimeHelper::formatTimeForDb($criteria->to), $query->params));
}
}

// Check for type
if (!empty($criteria->type)) {
$query->andWhere(DbHelper::parseParam('auditlog.type', $criteria->type, $query->params));
}

// Check for status
if (!empty($criteria->status)) {
$query->andWhere(DbHelper::parseParam('auditlog.status', $criteria->status, $query->params));
}

// Search
/**
* Apply search criteria.
*
* @param ElementCriteriaModel $search
* @param DbCommand $query
*/
private function applySearchCriteria(ElementCriteriaModel $criteria, DbCommand $query)
{
if (!empty($criteria->search)) {

// Always perform a LIKE search
Expand Down

0 comments on commit e24163d

Please sign in to comment.