예제 #1
0
 public static function logAuditEvent($moduleName, $eventName, $data = null, RedBeanModel $model = null, User $user = null)
 {
     assert('is_string($moduleName) && $moduleName != ""');
     assert('is_string($eventName)  && $eventName  != ""');
     if ($user === null) {
         $user = Yii::app()->user->userModel;
         if (!$user instanceof User) {
             throw new NoCurrentUserSecurityException();
         }
     }
     if ($eventName == ZurmoModule::AUDIT_EVENT_ITEM_VIEWED) {
         AuditEventsRecentlyViewedUtil::resolveNewRecentlyViewedModel($data[1], $model, AuditEventsRecentlyViewedUtil::RECENTLY_VIEWED_COUNT + 1);
     }
     if ($eventName == ZurmoModule::AUDIT_EVENT_ITEM_DELETED) {
         $modelClassName = get_class($model);
         AuditEventsRecentlyViewedUtil::deleteModelFromRecentlyViewed($modelClassName::getModuleClassName(), $model);
     }
     if ($eventName != ZurmoModule::AUDIT_EVENT_ITEM_VIEWED) {
         if (!AuditEvent::$isTableOptimized && !AUDITING_OPTIMIZED) {
             $auditEvent = new AuditEvent();
             $auditEvent->dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
             $auditEvent->moduleName = $moduleName;
             $auditEvent->eventName = $eventName;
             $auditEvent->user = $user;
             $auditEvent->modelClassName = $model !== null ? get_class($model) : null;
             $auditEvent->modelId = $model !== null ? $model->id : null;
             $auditEvent->serializedData = serialize($data);
             $saved = $auditEvent->save();
             AuditEvent::$isTableOptimized = true;
         } else {
             $sql = "insert into auditevent (datetime,\n                                                modulename,\n                                                eventname,\n                                                _user_id,\n                                                modelclassname,\n                                                modelid,\n                                                serializeddata)\n                        values ('" . DateTimeUtil::convertTimestampToDbFormatDateTime(time()) . "',\n                                '{$moduleName}',\n                                '{$eventName}',\n                                {$user->id}, " . ($model !== null ? "'" . get_class($model) . "', " : 'null, ') . ($model !== null ? "{$model->id}, " : 'null, ') . ":data)";
             ZurmoRedBean::exec($sql, array('data' => serialize($data))) !== null;
             $saved = true;
         }
         return $saved;
     }
 }
예제 #2
0
 protected static function makeRecentlyViewedView()
 {
     $items = AuditEventsRecentlyViewedUtil::getRecentlyViewedItemsByUser(Yii::app()->user->userModel, 10);
     return new RecentlyViewedView($items);
 }
 public function testDeleteModelFromRecentlyViewed()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     ZurmoConfigurationUtil::setForCurrentUserByModuleName('ZurmoModule', 'recentlyViewed', null);
     $account1 = new Account();
     $account1->name = 'Dooble1';
     $this->assertTrue($account1->save());
     $account2 = new Account();
     $account2->name = 'Dooble2';
     $this->assertTrue($account2->save());
     $account3 = new Account();
     $account3->name = 'Dooble3';
     $account3->owner = User::getByUsername('jimmy');
     $this->assertTrue($account3->save());
     //Now create some audit entries for the Item Viewed event.
     AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($account1), 'AccountsModule'), $account1);
     AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($account2), 'AccountsModule'), $account2);
     AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($account1), 'AccountsModule'), $account3);
     $content = AuditEventsRecentlyViewedUtil::getRecentlyViewedAjaxContentByUser(Yii::app()->user->userModel, 5);
     $this->assertContains('Dooble1', $content);
     $this->assertContains('Dooble2', $content);
     $this->assertContains('Dooble3', $content);
     AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_DELETED, strval($account1), $account1);
     $content = AuditEventsRecentlyViewedUtil::getRecentlyViewedAjaxContentByUser(Yii::app()->user->userModel, 5);
     $this->assertNotContains('Dooble1', $content);
     $this->assertContains('Dooble2', $content);
     $this->assertContains('Dooble3', $content);
 }