33namespace 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-
1211class 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}
0 commit comments