예제 #1
0
 /**
  * Finds all users by given search string. Searches for the users id,
  * part of the name or the username.
  * 
  * @param type $needle The needle to search for.
  * @return array
  */
 public static function searchUser($needle)
 {
     $result = array();
     $users = User::findBySQL("Nachname LIKE CONCAT('%', :needle, '%')\n                     OR Vorname LIKE CONCAT('%', :needle, '%')\n                     OR CONCAT(Nachname, ', ', Vorname) LIKE CONCAT('%', :needle, '%')\n                     OR CONCAT(Vorname, ' ', Nachname) LIKE CONCAT('%', :needle, '%')\n                     OR username LIKE CONCAT('%', :needle, '%')", array(':needle' => $needle));
     foreach ($users as $user) {
         $name = sprintf('%s (%s)', my_substr($user->getFullname(), 0, 20), $user->username);
         $result[] = array($user->getId(), $name);
     }
     // search for deleted users
     //
     // The name of the user is part of info field,
     // old id (still in DB) is in affected column.
     //
     // The log action "USER_DEL" was removed from the list of initially
     // registered log actions in the past.
     // Search for the user if it is still in database. If not, the search
     // for deleted users is not possible.
     $log_action_deleted_user = SimpleORMapCollection::createFromArray(LogAction::findByName('USER_DEL'))->first();
     if ($log_action_deleted_user) {
         $log_events_deleted_user = LogEvent::findBySQL("action_id = ? AND info LIKE CONCAT('%', ?, '%')", array($log_action_deleted_user->getId(), $needle));
         foreach ($log_events_deleted_user as $log_event) {
             $name = sprintf('%s (%s)', $log_event->info, _('gelöscht'));
             $result[] = array($log_event->affected_range_id, $name);
         }
     }
     return $result;
 }