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

Commit

Permalink
Fixed a bug where the date range didn't fully work
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Olde Hampsink committed Nov 10, 2015
1 parent 09d78f7 commit 03dd9d2
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 59 deletions.
2 changes: 1 addition & 1 deletion AuditLogPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getName()
*/
public function getVersion()
{
return '0.6.1';
return '0.6.2';
}

/**
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ Features:
- modifyAuditLogSortableAttributes
- Has events that you can listen to
- auditLog.onElementChanged

Roadmap:
- Log more ElementTypes (Tags, Globals, Assets)

Important:
The plugin's folder should be named "auditlog"

Changelog
=================
###0.6.2###
- Fixed a bug where the date range didn't fully work

###0.6.1###
- Added a registerAuditLogSources hook to provide custom sources/criteria
- Fixed Audit Log not being able to fetch a specific log item
Expand Down Expand Up @@ -94,4 +97,4 @@ Warning! This version is updated for Craft 2.3 and does NOT work on Craft 2.2
- Transformed AuditLog into an ElementType for easier sorting, filtering, searching and pagination

###0.1.0###
- Initial push to GitHub
- Initial push to GitHub
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "boboldehampsink/auditlog",
"description": "Audit Log Plugin for Craft CMS",
"authors": [
{
"name": "Bob Olde Hampsink",
"email": "b.oldehampsink@itmundi.nl"
}
],
{
"name": "Bob Olde Hampsink",
"email": "b.oldehampsink@itmundi.nl"
}
],
"type": "craft-plugin",
"require": {
"composer/installers": "~1.0"
}
}
}
5 changes: 2 additions & 3 deletions controllers/AuditLogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Handles requests for the Audit Log
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license http://buildwithcraft.com/license Craft License Agreement
* @license MIT
*
* @link http://github.com/boboldehampsink/auditlog
*/
Expand All @@ -20,7 +20,6 @@ class AuditLogController extends BaseController
*/
public function actionDownload()
{

// Get criteria
$criteria = craft()->elements->getCriteria('AuditLog', craft()->request->getParam('criteria'));

Expand Down
34 changes: 11 additions & 23 deletions elementtypes/AuditLogElementType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Makes the log behave as an Element Type
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down Expand Up @@ -58,7 +58,6 @@ public function getStatuses()
*/
public function defineTableAttributes($source = null)
{

// Define default attributes
$attributes = array(
'type' => Craft::t('Type'),
Expand Down Expand Up @@ -87,14 +86,11 @@ public function defineTableAttributes($source = null)
*/
public function getTableAttributeHtml(BaseElementModel $element, $attribute)
{

// First give plugins a chance to set this
$pluginAttributeHtml = craft()->plugins->callFirst('getAuditLogTableAttributeHtml', array($element, $attribute), true);

// Check if that had a valid result
if ($pluginAttributeHtml) {

// Return it
return $pluginAttributeHtml;
}

Expand All @@ -104,36 +100,30 @@ public function getTableAttributeHtml(BaseElementModel $element, $attribute)
// Format dates
case 'dateCreated':
case 'dateUpdated':

return craft()->dateFormatter->formatDateTime($element->$attribute);
break;

// Return clickable user link
case 'user':

$user = $element->getUser();

return $user ? '<a href="'.$user->getCpEditUrl().'">'.$user.'</a>' : Craft::t('Guest');
break;

// Return clickable event origin
case 'origin':

return '<a href="'.preg_replace('/'.craft()->config->get('cpTrigger').'\//', '', UrlHelper::getUrl($element->origin), 1).'">'.$element->origin.'</a>';
break;

// Return view changes button
case 'changes':

return '<a class="btn" href="'.UrlHelper::getCpUrl('auditlog/'.$element->id).'">'.Craft::t('View').'</a>';
break;

// Default behavior
default:

return $element->$attribute;
break;

}
}

Expand All @@ -150,8 +140,8 @@ public function defineCriteriaAttributes()
'origin' => AttributeType::String,
'modified' => AttributeType::DateTime,
'status' => AttributeType::String,
'before' => AttributeType::DateTime,
'after' => AttributeType::DateTime,
'from' => AttributeType::DateTime,
'to' => AttributeType::DateTime,
'order' => array(AttributeType::String, 'default' => 'auditlog.id desc'),
);
}
Expand Down Expand Up @@ -183,14 +173,14 @@ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $crit
$query->andWhere(DbHelper::parseParam('auditlog.id', $criteria->id, $query->params));
}

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

// Check for date before
if (!empty($criteria->before)) {
$query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', '<= '.DateTimeHelper::formatTimeForDb($criteria->before), $query->params));
// Check for date to
if (!empty($criteria->to)) {
$query->andWhere(DbHelper::parseDateParam('auditlog.dateUpdated', '<= '.DateTimeHelper::formatTimeForDb($criteria->to), $query->params));
}

// Check for type
Expand Down Expand Up @@ -244,7 +234,6 @@ public function populateElementModel($row)
*/
public function getSources($context = null)
{

// Get plugin settings
$settings = craft()->plugins->getPlugin('AuditLog')->getSettings();

Expand Down Expand Up @@ -308,7 +297,6 @@ public function getSources($context = null)
*/
public function defineSortableAttributes()
{

// Set modified first
$attributes['dateUpdated'] = Craft::t('Modified');

Expand Down
6 changes: 3 additions & 3 deletions models/AuditLogModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Contains the log data aswell as some constants
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down
6 changes: 3 additions & 3 deletions records/AuditLogRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Represents the Audit Log tables in the database
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down
6 changes: 3 additions & 3 deletions services/AuditLogService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Contains logics for logging
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down
6 changes: 3 additions & 3 deletions services/AuditLog_CategoryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Contains logics for logging categories
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down
6 changes: 3 additions & 3 deletions services/AuditLog_EntryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Contains logics for logging entries
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down
6 changes: 3 additions & 3 deletions services/AuditLog_UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* Contains logics for logging users
*
* @author Bob Olde Hampsink <b.oldehampsink@itmundi.nl>
* @copyright Copyright (c) 2015, author
* @license http://buildwithcraft.com/license Craft License Agreement
* @author Bob Olde Hampsink <b.oldehampsink@nerds.company>
* @copyright Copyright (c) 2015, Bob Olde Hampsink
* @license MIT
*
* @link http://github.com/boboldehampsink
*/
Expand Down
10 changes: 5 additions & 5 deletions templates/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ Craft.elementIndex = Craft.createElementIndex('AuditLog', $('#main'), {
showLocaleMenu: 'auto',
storageKey: 'elementindex.AuditLog',
criteria: {
after: {
from: {
date: $('#auditlog-modified-from-date').val()
},
before: {
to: {
date: $('#auditlog-modified-to-date').val()
}
}
Expand Down Expand Up @@ -89,10 +89,10 @@ $(document).on('change', 'input.hasDatepicker', function() {

// Get new criteria values
Craft.elementIndex.settings.criteria = {
after: {
from: {
date: $('#auditlog-modified-from-date').val()
},
before: {
to: {
date: $('#auditlog-modified-to-date').val()
}
};
Expand All @@ -101,4 +101,4 @@ $(document).on('change', 'input.hasDatepicker', function() {
Craft.elementIndex.updateElements();

});
{% endblock %}
{% endblock %}

0 comments on commit 03dd9d2

Please sign in to comment.