Beispiel #1
0
 /**
  * Main action to display contacts
  */
 function index_action($filter = null)
 {
     // Check if we need to add contacts
     $mps = MultiPersonSearch::load('contacts');
     $imported = 0;
     foreach ($mps->getAddedUsers() as $userId) {
         $user_to_add = User::find($userId);
         if ($user_to_add) {
             $new_contact = array('owner_id' => User::findCurrent()->id, 'user_id' => $user_to_add->id);
             if ($filter && $this->group) {
                 $new_contact['group_assignments'][] = array('statusgruppe_id' => $this->group->id, 'user_id' => $user_to_add->id);
             }
             $imported += (bool) Contact::import($new_contact)->store();
         }
     }
     if ($imported) {
         PageLayout::postMessage(MessageBox::success(sprintf(_("%s Kontakte wurden hinzugefügt."), $imported)));
     }
     $mps->clearSession();
     // write filter to local
     $this->filter = $filter;
     // Deal with navigation
     Navigation::activateItem('community/contacts');
     // Edit CSS for quicknavigation
     PageLayout::addStyle('div.letterlist span {color: #c3c8cc;}');
     if ($filter) {
         $selected = $this->group;
         $contacts = SimpleCollection::createFromArray(User::findMany($selected->members->pluck('user_id')));
     } else {
         $contacts = User::findCurrent()->contacts;
     }
     $this->allContacts = $contacts;
     // Retrive first letter and store in that contactgroup
     $this->contacts = array();
     foreach ($contacts as $contact) {
         $this->contacts[strtoupper(SimpleCollection::translitLatin1($contact->nachname[0]))][] = $contact;
     }
     // Humans are a lot better with sorted results
     ksort($this->contacts);
     $this->contacts = array_map(function ($g) {
         return SimpleCollection::createFromArray($g)->orderBy('nachname, vorname');
     }, $this->contacts);
     // Init sidebar
     $this->initSidebar($filter);
     // Init person search
     $mps = MultiPersonSearch::get('contacts')->setTitle(_('Kontakte hinzufügen'))->setDefaultSelectedUser($this->allContacts->pluck('user_id'))->setExecuteURL($this->url_for('contact/index/' . $filter))->setSearchObject(new StandardSearch('user_id'));
     // Set default title
     $this->title = _('Alle Kontakte');
     // If we have a group
     if ($selected) {
         // Set title of Table
         $this->title = $selected->name;
         // Set title of multipersonsearch
         $mps->setTitle(sprintf(_('Kontakte zu %s hinzufügen'), $selected->name));
         $mps->addQuickfilter(_('Kontakte'), User::findCurrent()->contacts->pluck('user_id'));
     }
     // Render multiperson search
     $this->multiPerson = $mps->render();
 }
 /**
  * sorts the collection by columns of contained elements and returns it
  *
  * works like sql order by:
  * first param is a string containing combinations of column names
  * and sort direction, separated by comma e.g.
  *  'name asc, nummer desc '
  *  sorts first by name ascending and then by nummer descending
  *  second param denotes the sort type (using PHP sort constants):
  *  SORT_LOCALE_STRING:
  *  compare items as strings, transliterate latin1 to ascii, case insensitiv, natural order for numbers
  *  SORT_NUMERIC:
  *  compare items as integers
  *  SORT_STRING:
  *  compare items as strings
  *  SORT_NATURAL:
  *  compare items as strings using "natural ordering"
  *  SORT_FLAG_CASE:
  *  can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively
  *
  * @param string $order columns to order by
  * @param integer $sort_flags
  * @return SimpleCollection the sorted collection
  */
 function orderBy($order, $sort_flags = SORT_LOCALE_STRING)
 {
     //('name asc, nummer desc ')
     $sort_locale = false;
     switch ($sort_flags) {
         case SORT_NATURAL:
             $sort_func = 'strnatcmp';
             break;
         case SORT_NATURAL | SORT_FLAG_CASE:
             $sort_func = 'strnatcasecmp';
             break;
         case SORT_STRING | SORT_FLAG_CASE:
             $sort_func = 'strcasecmp';
             break;
         case SORT_STRING:
             $sort_func = 'strcmp';
             break;
         case SORT_NUMERIC:
             $sort_func = function ($a, $b) {
                 return (int) $a - (int) $b;
             };
             break;
         case SORT_LOCALE_STRING:
         default:
             $sort_func = 'strnatcasecmp';
             $sort_locale = true;
     }
     $sorter = array();
     foreach (explode(',', $order) as $one) {
         $sorter[] = array_values(array_filter(array_map('trim', explode(' ', $one))));
     }
     $func = function ($d1, $d2) use($sorter, $sort_func, $sort_locale) {
         do {
             list($field, $dir) = current($sorter);
             if (!$sort_locale) {
                 $value1 = $d1[$field];
                 $value2 = $d2[$field];
             } else {
                 $value1 = SimpleCollection::translitLatin1(substr($d1[$field], 0, 100));
                 $value2 = SimpleCollection::translitLatin1(substr($d2[$field], 0, 100));
             }
             $ret = $sort_func($value1, $value2);
             if (strtolower($dir) == 'desc') {
                 $ret = $ret * -1;
             }
         } while ($ret === 0 && next($sorter));
         return $ret;
     };
     if (count($sorter)) {
         $this->uasort($func);
     }
     return $this;
 }
Beispiel #3
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();
 }