Kronolith::removeUserEvents PHP Method

removeUserEvents() public static method

Remove all events owned by the specified user in all calendars.
public static removeUserEvents ( string $user )
$user string The user name to delete events for.
    public static function removeUserEvents($user)
    {
        if (!$GLOBALS['registry']->isAdmin()) {
            throw new Horde_Exception_PermissionDenied();
        }
        try {
            $shares = $GLOBALS['injector']->getInstance('Kronolith_Shares')->listShares($user, array('perm' => Horde_Perms::EDIT));
        } catch (Horde_Share_Exception $e) {
            Horde::log($shares, 'ERR');
            throw new Kronolith_Exception($shares);
        }
        foreach (array_keys($shares) as $calendar) {
            $driver = self::getDriver(null, $calendar);
            $events = $driver->listEvents(null, null, array('cover_dates' => false));
            $uids = array();
            foreach ($events as $dayevents) {
                foreach ($dayevents as $event) {
                    $uids[] = $event->uid;
                }
            }
            foreach ($uids as $uid) {
                $event = $driver->getByUID($uid, array($calendar));
                if ($event->creator == $user) {
                    $driver->deleteEvent($event->id);
                }
            }
        }
    }

Usage Example

Example #1
0
 /**
  */
 public function removeUserData($user)
 {
     $error = false;
     // Remove all events owned by the user in all calendars.
     Kronolith::removeUserEvents($user);
     // Get the shares owned by the user being deleted.
     try {
         $kronolith_shares = $GLOBALS['injector']->getInstance('Kronolith_Shares');
         $shares = $kronolith_shares->listShares($user, array('attributes' => $user));
         foreach ($shares as $share) {
             $kronolith_shares->removeShare($share);
         }
     } catch (Exception $e) {
         Horde::log($e, 'NOTICE');
         $error = true;
     }
     /* Get a list of all shares this user has perms to and remove the
      * perms */
     try {
         $shares = $kronolith_shares->listShares($user);
         foreach ($shares as $share) {
             $share->removeUser($user);
         }
     } catch (Horde_Share_Exception $e) {
         Horde::log($e, 'NOTICE');
         $error = true;
     }
     if ($error) {
         throw new Kronolith_Exception(sprintf(_("There was an error removing calendars for %s. Details have been logged."), $user));
     }
 }