2 /***********************************************************************/
4 /***********************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /***********************************************************************/
16 * Implementation of supported services backed using ATutor's DB Fetcher
17 * Check shindig/php/src/social/spi/ for the list of services within the interfaces.
20 function debug($var, $title='') {
21 echo '<pre style="border: 1px black solid; padding: 0px; margin: 10px;" title="debugging box">';
23 echo '<h4>'.$title.'</h4>';
28 $str = ob_get_contents();
31 $str = str_replace('<', '<', $str);
33 $str = str_replace('[', '<span style="color: red; font-weight: bold;">[', $str);
34 $str = str_replace(']', ']</span>', $str);
35 $str = str_replace('=>', '<span style="color: blue; font-weight: bold;">=></span>', $str);
36 $str = str_replace('Array', '<span style="color: purple; font-weight: bold;">Array</span>', $str);
42 * Get the set of user id's from a user or collection of users, and group
44 protected function getIdSet($user, GroupId $group, SecurityToken $token) {
46 if ($user instanceof UserId) {
47 $userId = $user->getUserId($token);
49 return array($userId);
51 switch ($group->getType()) {
55 $friendIds = ATutorDbFetcher::get()->getFriendIds($userId);
56 if (is_array($friendIds) && count($friendIds)) {
64 } elseif (is_array($user)) {
66 foreach ($user as $id) {
67 $ids = array_merge($ids, $this->getIdSet($id, $group, $token));
74 * Determines whether the input is a valid key. Valid keys match the regular
75 * expression [\w\-\.]+.
77 * @param key the key to validate.
78 * @return true if the key is a valid appdata key, false otherwise.
80 public static function isValidKey($key) {
84 for ($i = 0; $i < strlen($key); ++ $i) {
85 $c = substr($key, $i, 1);
86 if (($c >= 'a' && $c <= 'z') || ($c >= 'A' && $c <= 'Z') || ($c >= '0' && $c <= '9') || ($c == '-') || ($c == '_') || ($c == '.')) {
94 protected function sortPersonResults(&$people, $options) {
95 if (! $options->getSortBy()) {
96 return true; // trivially sorted
98 // for now, ATutor can only sort by displayName, which also demonstrates returning sorted: false
99 if ($options->getSortBy() != 'displayName') {
102 usort($people, array($this, 'comparator'));
103 if ($options->getSortOrder() != CollectionOptions::SORT_ORDER_ASCENDING) {
104 $people = array_reverse($people);
109 protected function comparator($person, $person1) {
110 $name = ($person instanceof Person ? $person->getDisplayName() : $person['displayName']);
111 $name1 = ($person1 instanceof Person ? $person1->getDisplayName() : $person1['displayName']);
112 return strnatcasecmp($name, $name1);