コード例 #1
0
ファイル: StudipLog.class.php プロジェクト: ratbird/hope
 /**
  * Logs an event to the database after a certain action took place along with
  * the ids of the range object the action possibly affected. You can provide
  * additional info as well as debug information.
  * 
  * @param String $action_name     Name of the action that took place 
  * @param mixed  $affected   Range id that was affected by the action, if any
  * @param mixed  $coaffected Range id that was possibly affected as well
  * @param mixed  $info       Information to add to the event
  * @param mixed  $dbg_info   Debug information to add to the event
  * @param mixed  $user_id    Provide null for the current user id
  **/
 public static function log($action_name, $affected = null, $coaffected = null, $info = null, $dbg_info = null, $user_id = null)
 {
     $log_action = SimpleORMapCollection::createFromArray(LogAction::findByName($action_name))->first();
     if (!$log_action) {
         // Action doesn't exist -> LOG_ERROR
         $debug = sprintf('EventLog::log(%s,%s,%s,%s,%s) for user %s', $log_action->name, $affected, $coaffected, $info, $dbg_info, $user_id);
         self::log('LOG_ERROR', null, null, null, $debug);
         return false;
     }
     if ($log_action->isActive()) {
         // automagically set current user as agent
         if (!$user_id) {
             $user_id = $GLOBALS['auth']->auth['uid'];
         }
         $log_event = new LogEvent();
         $log_event->user_id = $user_id;
         $log_event->action_id = $log_action->getId();
         $log_event->affected_range_id = $affected;
         $log_event->coaffected_range_id = $coaffected;
         $log_event->info = $info;
         $log_event->dbg_info = $dbg_info;
         $log_event->store();
         return true;
     }
     return false;
 }