Skip to content

Commit 86a7431

Browse files
committed
Resolved #4, More intuitive order of parameters and add default values
1 parent af91721 commit 86a7431

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
"Dframe\\ActivityLog\\Demo\\": "demo/app/"
2828
}
2929
},
30-
"require": {},
30+
"require": {
31+
"php": ">=7.0",
32+
"ext-json": "*"
33+
},
3134
"require-dev": {
3235
"dframe/database": "^1.4"
3336
},

src/Activity.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
namespace Dframe\ActivityLog;
44

55
/**
6-
* Dframe/activityLog
6+
* Dframe/ActivityLog
77
* Copyright (c) Sławomir Kaleta
88
*
99
* @license https://github.com/dusta/activityLog/blob/master/LICENCE
1010
*/
11-
1211
class Activity
1312
{
1413

@@ -18,7 +17,7 @@ class Activity
1817
*
1918
* @return object
2019
*/
21-
public function __construct($driver, $loggedId)
20+
public function __construct($driver, $loggedId = null)
2221
{
2322
$this->driver = $driver;
2423
$this->loggedId = $loggedId;
@@ -99,7 +98,6 @@ public function log(string $log)
9998
*/
10099
public function push()
101100
{
102-
$dateUTC = new \DateTime("now", new \DateTimeZone($this->dateTimeZone));
103101
$push = $this->driver->push($this->loggedId, $this->on ?? '', ['entity' => $this->entityType, 'data' => $this->entity], $this->log);
104102
if ($push['return'] == true) {
105103
return ['return' => true];
@@ -120,30 +118,33 @@ public function logsCount($whereArray)
120118
}
121119

122120
/**
123-
* @param int $start
124-
* @param int $limit
125121
* @param array $where
126122
* @param string $order
127123
* @param string $sort
124+
* @param int $limit
125+
* @param int $start
128126
*
129127
* @return array
130128
*/
131-
public function logs($start, $limit, $where, $order, $sort)
129+
public function logs($where = [], $order = 'id', $sort = 'DESC', $limit = 30, $start = 0)
132130
{
133-
$logs = $this->driver->logs($start, $limit, $where, $order, $sort);
131+
$logs = $this->driver->logs($where, $order, $sort, $limit, $start);
132+
if (isset($logs['return']) AND $logs['return'] === true) {
133+
foreach ($logs['data'] as $key => $value) {
134+
if (isset($value['log_type'])) {
135+
$explode = explode(".", $value['log_type']);
136+
$table = $explode[0];
137+
$entity = new $value['log_entity'];
138+
$columns = $entity->interpreter($explode[0]);
134139

135-
foreach ($logs['data'] as $key => $value) {
136-
$explode = explode(".", $value['log_type']);
137-
$table = $explode[0];
138-
$entity = new $value['log_entity'];
139-
$columns = $entity->interpreter($explode[0]);
140+
$logs['data'][$key]['table'] = $this->driver->readTypes($table, $columns, [$explode['1'] => $value['changed_id']])['data'];
141+
}
142+
}
140143

141-
$where = [(string)$value['log_type'] => (int)$value['changed_id']];
142144

143-
$logs['data'][$key]['table'] = $this->driver->readTypes($table, $columns, [$explode['1'] => $value['changed_id']])['data'];
145+
return ['return' => true, 'data' => $logs];
144146
}
145147

146-
147-
return ['return' => true, 'data' => $logs];
148+
return ['return' => false];
148149
}
149150
}

src/Driver.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
namespace Dframe\ActivityLog;
44

5+
/**
6+
* Interface Driver
7+
* Copyright (c) Sławomir Kaleta
8+
*
9+
* @license https://github.com/dusta/activityLog/blob/master/LICENCE
10+
*/
511
interface Driver
612
{
713
/**

0 commit comments

Comments
 (0)