Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
friendspicker.php
Go to the documentation of this file.
1 <?php
18 elgg_load_js('elgg.friendspicker');
19 elgg_load_js('jquery.easing');
20 
21 
22 $chararray = elgg_echo('friendspicker:chararray');
23 
24 // Initialise name
25 if (!isset($vars['name'])) {
26  $name = "friend";
27 } else {
28  $name = $vars['name'];
29 }
30 
31 // Are we highlighting default or all?
32 if (empty($vars['highlight'])) {
33  $vars['highlight'] = 'default';
34 }
35 if ($vars['highlight'] != 'all') {
36  $vars['highlight'] = 'default';
37 }
38 
39 // Initialise values
40 if (!isset($vars['value'])) {
41  $vars['value'] = array();
42 } else {
43  if (!is_array($vars['value'])) {
44  $vars['value'] = (int) $vars['value'];
45  $vars['value'] = array($vars['value']);
46  }
47 }
48 
49 // Initialise whether we're calling back or not
50 if (isset($vars['callback'])) {
51  $callback = $vars['callback'];
52 } else {
53  $callback = false;
54 }
55 
56 // We need to count the number of friends pickers on the page.
57 if (!isset($vars['friendspicker'])) {
58  global $friendspicker;
59  if (!isset($friendspicker)) {
60  $friendspicker = 0;
61  }
62  $friendspicker++;
63 } else {
64  $friendspicker = $vars['friendspicker'];
65 }
66 
67 $users = array();
68 $activeletters = array();
69 
70 // Are we displaying form tags and submit buttons?
71 // (If we've been given a target, then yes! Otherwise, no.)
72 if (isset($vars['formtarget'])) {
73  $formtarget = $vars['formtarget'];
74 } else {
75  $formtarget = false;
76 }
77 
78 // Sort users by letter
79 if (is_array($vars['entities']) && sizeof($vars['entities'])) {
80  foreach($vars['entities'] as $user) {
81  $letter = elgg_strtoupper(elgg_substr($user->name, 0, 1));
82 
83  if (!elgg_substr_count($chararray, $letter)) {
84  $letter = "*";
85  }
86  if (!isset($users[$letter])) {
87  $users[$letter] = array();
88  }
89  $users[$letter][$user->guid] = $user;
90  }
91 }
92 
93 // sort users in letters alphabetically
94 foreach ($users as $letter => $letter_users) {
95  usort($letter_users, create_function('$a, $b', '
96  return strcasecmp($a->name, $b->name);
97  '));
98  $users[$letter] = $letter_users;
99 }
100 
101 if (!$callback) {
102  ?>
103 
104  <div class="friends-picker-main-wrapper">
105 
106  <?php
107 
108  if (isset($vars['content'])) {
109  echo $vars['content'];
110  }
111  ?>
112 
113  <div id="friends-picker_placeholder<?php echo $friendspicker; ?>">
114 
115  <?php
116 }
117 
118 if (!isset($vars['replacement'])) {
119  if ($formtarget) {
120 ?>
121 <?php //@todo JS 1.8: no ?>
122 <script>
123 require(['elgg', 'jquery'], function(elgg, $) {
124  $(function () {
125  $('#collectionMembersForm<?php echo $friendspicker; ?>').submit(function() {
126  var inputs = [];
127  $(':input', this).each(function() {
128  if (this.type != 'checkbox' || (this.type == 'checkbox' && this.checked != false)) {
129  inputs.push(this.name + '=' + escape(this.value));
130  }
131  });
132  $.ajax({
133  type: "POST",
134  data: inputs.join('&'),
135  url: this.action,
136  success: function(){
137  $('a.collectionmembers<?php echo $friendspicker; ?>').click();
138  }
139 
140  });
141  return false;
142  });
143  });
144 });
145 </script>
146 
147 <!-- Collection members form -->
148 <form id="collectionMembersForm<?php echo $friendspicker; ?>" action="<?php echo $formtarget; ?>" method="post"> <!-- action="" method=""> -->
149 
150 <?php
151  echo elgg_view('input/securitytoken');
152  echo elgg_view('input/hidden', array(
153  'name' => 'collection_id',
154  'value' => $vars['collection_id'],
155  ));
156  }
157 ?>
158 
159 <div class="friends-picker-wrapper">
160 <div id="friends-picker<?php echo $friendspicker; ?>">
161  <div class="friends-picker-container">
162 <?php
163 
164 // Initialise letters
165  $chararray .= "*";
166  $letter = elgg_substr($chararray, 0, 1);
167  $letpos = 0;
168  while (1 == 1) {
169  ?>
170  <div class="panel" title="<?php echo $letter; ?>">
171  <div class="wrapper">
172  <h3><?php echo $letter; ?></h3>
173  <?php
174 
175  if (isset($users[$letter])) {
176  ksort($users[$letter]);
177 
178  echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
179  $col = 0;
180 
181  foreach($users[$letter] as $friend) {
182  if ($col == 0) {
183  echo "<tr>";
184  }
185 
186  //echo "<p>" . $user->name . "</p>";
187  $label = elgg_view_entity_icon($friend, 'tiny', array('use_hover' => false));
188  $options[$label] = $friend->getGUID();
189 
190  if ($vars['highlight'] == 'all' && !in_array($letter,$activeletters)) {
191  $activeletters[] = $letter;
192  }
193 
194 
195  if (in_array($friend->getGUID(),$vars['value'])) {
196  $checked = "checked = \"checked\"";
197  if (!in_array($letter,$activeletters) && $vars['highlight'] == 'default') {
198  $activeletters[] = $letter;
199  }
200  } else {
201  $checked = "";
202  }
203  ?>
204 
205  <td>
206 
207  <input type="checkbox" <?php echo $checked; ?> name="<?php echo $name; ?>[]" value="<?php echo $options[$label]; ?>" />
208 
209  </td>
210 
211  <td>
212 
213  <div style="width: 25px; margin-bottom: 15px;">
214  <?php
215  echo $label;
216  ?>
217  </div>
218  </td>
219  <td style="width: 200px; padding: 5px;">
220  <?php echo $friend->name; ?>
221  </td>
222  <?php
223  $col++;
224  if ($col == 3){
225  echo "</tr>";
226  $col = 0;
227  }
228  }
229  if ($col < 3) {
230  echo "</tr>";
231  }
232 
233  echo "</table>";
234  }
235 
236 ?>
237 
238  </div>
239  </div>
240 <?php
241 
242  $substr = elgg_substr($chararray, elgg_strlen($chararray) - 1, 1);
243  if ($letter == $substr) {
244  break;
245  }
246  //$letter++;
247  $letpos++;
248  $letter = elgg_substr($chararray, $letpos, 1);
249  }
250 
251 ?>
252  </div>
253 
254 <?php
255 
256 if ($formtarget) {
257 
258  if (isset($vars['formcontents']))
259  echo $vars['formcontents'];
260 
261 ?>
262  <div class="clearfix"></div>
263  <div class="friendspicker-savebuttons">
264  <input type="submit" class="elgg-button elgg-button-submit" value="<?php echo elgg_echo('save'); ?>" />
265  <input type="button" class="elgg-button elgg-button-cancel" value="<?php echo elgg_echo('cancel'); ?>" onclick="$('a.collectionmembers<?php echo $friendspicker; ?>').click();" />
266  <br /></div>
267  </form>
268 
269 <?php
270 
271 }
272 
273 ?>
274 
275 </div>
276 </div>
277 
278 <?php
279 } else {
280  echo $vars['replacement'];
281 }
282 if (!$callback) {
283 
284 ?>
285 
286 </div>
287 </div>
288 
289 
290 <?php
291 
292 }
293 
294 if (isset($vars['replacement'])) {
295  return;
296 }
297 
298 ?>
299 <script>
300 require(['jquery'], function($) {
301  $(function () {
302  // initialise picker
303  $("div#friends-picker<?php echo $friendspicker; ?>").friendsPicker(<?php echo $friendspicker; ?>);
304 
305  <?php
306  // manually add class to corresponding tab for panels that have content
307  if (sizeof($activeletters) > 0) {
308  //$chararray = elgg_echo('friendspicker:chararray');
309  foreach($activeletters as $letter) {
310  $tab = elgg_strpos($chararray, $letter) + 1;
311  ?>
312  $("div#friends-picker-navigation<?php echo $friendspicker; ?> li.tab<?php echo $tab; ?> a").addClass("tabHasContent");
313  <?php
314  }
315  }
316  ?>
317  });
318 });
319 </script>
elgg_strtoupper()
Wrapper function for mb_strtoupper().
Definition: mb_wrapper.php:191
action($action, $forwarder="")
Perform an action.
Definition: actions.php:47
if(!$site) if(!($site instanceof ElggSite)) $site url
$activeletters
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$site name
$friend
Definition: add.php:11
$vars['entity']
$options
Elgg admin footer.
Definition: footer.php:6
$chararray
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:72
elgg module widget elgg head h3
$users
Definition: newest.php:3
td
Definition: admin.css.php:63
elgg_strpos()
Wrapper function for mb_strpos().
Definition: mb_wrapper.php:89
$user
Definition: ban.php:13
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
elgg_substr()
Wrapper function for mb_substr().
Definition: mb_wrapper.php:225
const elgg
Definition: elgg.js.php:92
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:208
elgg_view_entity_icon(\ElggEntity $entity, $size= 'medium', $vars=array())
View the icon of an entity.
Definition: views.php:895
elgg_substr_count()
Wrapper function for mb_substr_count().
Definition: mb_wrapper.php:208
elgg river item form
elgg river item input[type=text]
$friendspicker