| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- /**
- * User Activity
- * $_SESSION[{$_sesKey}] = array(
- * {id_zasob: int}
- * , {id_zasob: int, task: 'edit', id_item: int}
- * , {id_zasob: int}
- * ...
- * );
- */
- class UserActivity {
- public static $_sesKey = 'UserActivityList';
- public static $_limit = 5;
- public static function showListInContainer() {
- $list = self::showSimpleList();
- if (empty($list)) {
- return;
- }
- ?>
- <div class="container">
- <h3>Ostatnia aktywność:</h3>
- <?php echo $list; ?>
- </div>
- <?php
- }
- public static function showSimpleList() {
- $out = '';
- $listaOut = array();
- Lib::loadClass('ProcesHelper');
- $list = self::getRawList();
- if(V::get('DBG_ACT', '', $_GET)){echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($list);echo'</pre>';}
- $list = array_reverse($list);
- foreach ($list as $activity) {
- $zasobObj = ProcesHelper::getZasobTableInfo($activity->id_zasob);
- if (!$zasobObj) {
- continue;
- }
- $userAcl = User::getAcl();
- $userAcl->fetchGroups();
- if (!$userAcl->hasTableAcl($zasobObj->ID)) {
- continue;
- }
- $tblAcl = $userAcl->getTableAcl($zasobObj->ID);
- if (!$tblAcl) {
- continue;
- }
- $listAdd = '';
- if (!empty($activity->task) && !empty($activity->id_item)) {
- if ($activity->task == 'edit') {
- $listAdd .= " - edycja rekordu " . '<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobObj->ID}#EDIT/{$activity->id_item}" . '">' . $activity->id_item . '</a>';
- }
- }
- $listaOut[] = '<a href="' . "index.php?MENU_INIT=VIEWTABLE_AJAX&ZASOB_ID={$zasobObj->ID}" . '">' . $tblAcl->getShortLabel() . '</a>';
- }
- if (!empty($listaOut)) {
- $out = '<ul><li>' . implode('</li><li>', $listaOut) . '</li></ul>';
- }
- return $out;
- }
- public static function _createSes() {
- if (!isset($_SESSION[self::$_sesKey])) {
- $_SESSION[self::$_sesKey] = array();
- }
- }
- public static function add($id_zasob, $task = '', $id_item = null) {
- //unset($_SESSION[self::$_sesKey]);
- $activity = null;
- self::_createSes();
- $activity = new stdClass();
- $activity->id_zasob = $id_zasob;
- if ($task) {
- $activity->task = $task;
- }
- if ($id_item) {
- $activity->id_item = $id_item;
- }
- if (!$activity) {
- return;
- }
- $lastActivity = self::getRawLastActivity();
- if ($lastActivity) {
- if ($lastActivity->id_zasob == $activity->id_zasob) {
- if (isset($activity->task) && isset($lastActivity->task)) {
- if ($activity->task == $lastActivity->task
- && $activity->id_item == $lastActivity->id_item
- ) {
- return;
- }
- } else {
- return;
- }
- }
- }
- $_SESSION[self::$_sesKey][] = $activity;
- self::_gc();
- }
- public static function getRawList() {
- self::_createSes();
- return $_SESSION[self::$_sesKey];
- }
- public static function getRawLastActivity() {
- $list = self::getRawList();
- if (!empty($list)) {
- $lastActivity = end($list);
- return $lastActivity;
- }
- return null;
- }
- public static function getListTotal() {
- $list = self::getRawList();
- return count($list);
- }
- public static function _gc($recLimit = 3) {
- if ($recLimit < 0) {
- return;
- }
- $total = count($_SESSION[self::$_sesKey]);
- if ($total > self::$_limit) {
- array_shift($_SESSION[self::$_sesKey]);
- self::_gc(--$recLimit);
- }
- }
- }
|