public function create(ModelAbstract $model)
 {
     if ($model->type == ReportModel::AUDIT_LOG) {
         return $this->_fakeWatcherAuditLog($model);
     }
     $filterList = $this->buildFilterList(array('tags' => 'context_' . \App::getUserLogged()->organizationId));
     $list = $this->listAll($filterList);
     if (\App::getUserLogged()->isApiAuthUser()) {
         $limit = \App::config('reports.maxReportsPerApiId', 100);
     } else {
         $limit = \App::config('reports.maxReportsPerUser', 20);
     }
     if ($list->count() >= $limit) {
         throw new \Application\Exceptions\NotAllowedException("Create report Operation is not " . "allowed: Too many reports created. The limit is " . $limit . " generated reports", ValidationCodes::REPORT_LIMIT_REACHED);
     }
     return ReportAsyncService::getInstance()->create($model);
 }
 public static function createModelActionEvent($action, PersistentAbstract $model)
 {
     $eventData = array('action' => $action);
     try {
         if (\App::getUserLogged() && \App::getUserLogged()->id) {
             $eventData['userId'] = \App::getUserLogged()->id;
         }
     } catch (\Exception $e) {
     }
     $event = new EventModel();
     $event->namespace = 'connectivity';
     $event->entityType = $model->getResourceId();
     $event->entityId = $model->id;
     $event->action = $action;
     $event->eventData = $eventData;
     $event->pushEventData = true;
     $event->hiddenData = array('model' => $model->exportData());
     return $event;
 }
 protected function _convertDateToDateTime($date, $h = 0, $m = 0, $s = 0)
 {
     $user = \App::getUserLogged();
     $timezone = $user->timezone ?: 'GMT';
     $dateTime = date_create_from_format('Ymd', $date, new \DateTimeZone($timezone));
     $dateTime->setTime($h, $m, $s);
     $dateTime->setTimezone(new \DateTimeZone('UTC'));
     return $dateTime->format('Y-m-d\\TH:i:s\\Z');
 }
 public function impersonate($org = null)
 {
     $adapter = new \App_Auth_Adapter_Impersonation();
     $user = \App::getUserLogged();
     if ($org) {
         $adapter->setCredentials($org->getId());
     }
     $auth = \Zend_Auth::getInstance();
     $result = $auth->authenticate($adapter);
     if ($result->isValid()) {
         if ($org) {
             \App::audit('User start impersonating organization with Id ' . $org->getId(), $user);
         } else {
             \App::audit('User stop impersonating organization with Id ' . $user->getOrganizationId(), $user);
         }
     } else {
         throw UnexpectedException("Unexpected error triing to impersonate");
     }
 }