Esempio n. 1
0
 public function before_filter(&$action, &$args)
 {
     parent::before_filter($action, $args);
     // Load statusgroups
     $this->groups = SimpleCollection::createFromArray(Statusgruppen::findByRange_id(User::findCurrent()->id));
     // Load requested group
     if ($args[0]) {
         $this->group = $this->groups->findOneBy('statusgruppe_id', $args[0]);
         //Check for cheaters
         if ($this->group->range_id != User::findCurrent()->id) {
             throw new AccessDeniedException();
         }
     }
 }
Esempio n. 2
0
 /**
  * List all contact groups of a user
  *
  * @get /user/:user_id/contact_groups
  */
 public function getUserContactGroups($user_id)
 {
     if ($GLOBALS['user']->id !== $user_id) {
         $this->error(401);
     }
     $contact_groups = \SimpleCollection::createFromArray(\Statusgruppen::findByRange_id($GLOBALS['user']->id))->orderBy('name ASC');
     $total = count($contact_groups);
     $contact_groups = $contact_groups->limit($this->offset, $this->limit);
     $contact_groups_json = $this->contactGroupsToJSON($contact_groups);
     $this->etag(md5(serialize($contact_groups_json)));
     return $this->paginated($contact_groups_json, $total, compact('user_id'));
 }
Esempio n. 3
0
 /**
  * Retrieves all contact groups (statusgruppen) owned by the given user
  * where at least one member has granted access to his calender for the user.
  *
  * @param string $user_id User id of the owner.
  * @return type
  */
 public static function getGroups($user_id)
 {
     $groups = array();
     $calendar_owners = CalendarUser::getOwners($user_id)->pluck('owner_id');
     $sg_groups = SimpleORMapCollection::createFromArray(Statusgruppen::findByRange_id($user_id))->orderBy('position')->pluck('statusgruppe_id');
     if (sizeof($calendar_owners)) {
         $sg_users = StatusgruppeUser::findBySQL('statusgruppe_id IN(?) AND user_id IN(?)', array($sg_groups, $calendar_owners));
         foreach ($sg_users as $sg_user) {
             $groups[$sg_user->group->id] = $sg_user->group;
         }
     }
     return $groups;
 }
Esempio n. 4
0
 public function manage_access_action($range_id = null)
 {
     $this->range_id = $range_id ?: $this->range_id;
     $this->calendar = new SingleCalendar($this->range_id);
     $all_calendar_users = CalendarUser::getUsers($this->calendar->getRangeId());
     $this->filter_groups = Statusgruppen::findByRange_id($this->calendar->getRangeId());
     $this->users = array();
     $this->group_filter_selected = Request::option('group_filter', 'list');
     if ($this->group_filter_selected != 'list') {
         $contact_group = Statusgruppen::find($this->group_filter_selected);
         $calendar_users = array();
         foreach ($contact_group->members as $member) {
             $calendar_users[] = new CalendarUser(array($this->calendar->getRangeId(), $member->user_id));
         }
         $this->calendar_users = SimpleORMapCollection::createFromArray($calendar_users);
     } else {
         $this->group_filter_selected = 'list';
         $this->calendar_users = $all_calendar_users;
     }
     $this->own_perms = array();
     foreach ($this->calendar_users as $calendar_user) {
         $other_user = CalendarUser::find(array($calendar_user->user_id, $this->calendar->getRangeId()));
         if ($other_user) {
             $this->own_perms[$calendar_user->user_id] = $other_user->permission;
         } else {
             $this->own_perms[$calendar_user->user_id] = Calendar::PERMISSION_FORBIDDEN;
         }
         $this->users[strtoupper(SimpleCollection::translitLatin1($calendar_user->nachname[0]))][] = $calendar_user;
     }
     ksort($this->users);
     $this->users = array_map(function ($g) {
         return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname');
     }, $this->users);
     $this->mps = MultiPersonSearch::get('calendar-manage_access')->setTitle(_('Personhinzufügen'))->setLinkText(_('Person hinzufügen'))->setDefaultSelectedUser($all_calendar_users->pluck('user_id'))->setJSFunctionOnSubmit('STUDIP.CalendarDialog.closeMps')->setExecuteURL($this->url_for('calendar/single/add_users/' . $this->calendar->getRangeId()))->setSearchObject(new StandardSearch('user_id'));
     PageLayout::setTitle($this->getTitle($this->calendar, _('Kalender freigeben')));
     $this->createSidebar('manage_access', $this->calendar);
     $this->createSidebarFilter();
 }