Пример #1
0
 public function getAudits($type = "", \DateTime $start_time = NULL, \DateTime $end_time = NULL)
 {
     if (!is_string($type) || !c\AuditTypes::isAuditType($type)) {
         if (self::DEBUG && !is_string($type)) {
             u\DebugUtility::out("Not a string");
         }
         throw new e\NoSuchTypeException(c\M::WRONG_AUDIT_TYPE);
     }
     $start = false;
     $end = false;
     if (isset($start_time)) {
         if (isset($end_time)) {
             if ($end_time < $start_time) {
                 throw new \Exception(c\M::SMALLER_END_TIME);
             }
             $end = true;
         }
         $start = true;
     }
     $a_std = new \stdClass();
     // unable to test with user, group, role
     if ($this->getType() == User::TYPE) {
         $a_std->username = $this->getName();
     } else {
         if ($this->getType() == Group::TYPE) {
             $a_std->groupname = $this->getName();
         } else {
             if ($this->getType() == Role::TYPE) {
                 $a_std->rolename = $this->getName();
             } else {
                 $a_std->identifier->id = $this->getId();
                 $a_std->identifier->type = $this->getType();
             }
         }
     }
     if ($type != "") {
         $a_std->auditType = $type;
     }
     $service = $this->getService();
     $service->readAudits($a_std);
     $audits = array();
     if ($service->isSuccessful()) {
         if (self::DEBUG) {
             u\DebugUtility::dump($service->getAudits());
         }
         $audit_stds = $service->getAudits()->audit;
         if (isset($audit_stds) && !is_array($audit_stds)) {
             $audit_stds = array($audit_stds);
         }
         $count = count($audit_stds);
         if ($count > 0) {
             foreach ($audit_stds as $audit_std) {
                 if (self::DEBUG && self::DUMP) {
                     u\DebugUtility::dump($audit_std);
                 }
                 $audit = new Audit($service, $audit_std);
                 if ($start && $audit->getDate() >= $start_time) {
                     if ($end && $audit->getDate() <= $end_time) {
                         $audits[] = $audit;
                     } else {
                         if (!$end) {
                             $audits[] = $audit;
                         }
                     }
                 } else {
                     if (!$start) {
                         if ($end && $audit->getDate() <= $end_time) {
                             $audits[] = $audit;
                         } else {
                             if (!$end) {
                                 $audits[] = $audit;
                             }
                         }
                     }
                 }
             }
             usort($audits, self::NAME_SPACE . "\\" . 'Audit::compare');
         }
     } else {
         echo $service->getMessage();
     }
     return $audits;
 }
 public static function compareDescending(Audit $a1, Audit $a2)
 {
     if ($a1->getDate() == $a2->getDate()) {
         return 0;
     } else {
         if ($a1->getDate() < $a2->getDate()) {
             return 1;
         } else {
             return -1;
         }
     }
 }