BAOBAB
co_user_collection.class.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************************************************************************/
26 defined( 'LGV_DBF_CATCHER' ) or die ( 'Cannot Execute Directly' ); // Makes sure that this file is in the correct context.
27 
28 CO_Config::require_extension_class('tco_collection.interface.php');
29 require_once(CO_Config::db_class_dir().'/co_main_db_record.class.php');
30 
31 $lang = CO_Config::$lang;
32 
33 global $g_lang_override; // This allows us to override the configured language at initiation time.
34 
35 if (isset($g_lang_override) && $g_lang_override && file_exists(CO_Config::lang_class_dir().'/'.$g_lang_override.'.php')) {
37 }
38 
39 $lang_file = CO_Config::badger_lang_class_dir().'/'.$lang.'.php';
40 $lang_common_file = CO_Config::badger_lang_class_dir().'/common.inc.php';
41 
42 if ( !defined('LGV_LANG_CATCHER') ) {
43  define('LGV_LANG_CATCHER', 1);
44 }
45 
46 require_once($lang_file);
47 require_once($lang_common_file);
48 
49 /***************************************************************************************************************************/
69  use tCO_Collection; // These are the built-in collection methods.
70 
71  private $_login_object = NULL;
72 
73  /***********************/
77  protected function _load_login() {
78  $ret = false;
79  // Tag 0 contains the ID of the user login (in the security DB) for this user.
80  $login_id = isset($this->tags()[0]) ? intval($this->tags()[0]) : 0;
81 
82  if (0 < $login_id) {
83  $my_login_object = $this->get_access_object()->get_single_security_record_by_id($login_id);
84 
85  if (isset($my_login_object) && ($my_login_object instanceof CO_Security_Login)) {
86  $this->_login_object = $my_login_object;
87  $ret = true;
88  } elseif (!($my_login_object instanceof CO_Security_Login)) {
92  __FILE__,
93  __LINE__,
94  __METHOD__
95  );
96  } else {
100  __FILE__,
101  __LINE__,
102  __METHOD__
103  );
104  }
105  } else {
109  __FILE__,
110  __LINE__,
111  __METHOD__
112  );
113  }
114 
115  return $ret;
116  }
117 
118  /***********************************************************************************************************************/
119  /***********************/
123  public function __construct( $in_db_object = NULL,
124  $in_db_result = NULL,
125  $in_owner_id = NULL,
126  $in_tags_array = NULL
127  ) {
128 
129  $this->_container = Array();
130  $this->_login_object = NULL;
131 
132  parent::__construct($in_db_object, $in_db_result, $in_owner_id, $in_tags_array);
133 
134  $this->class_description = "This is a 'Collection' Class for Users.";
135  }
136 
137  /***********************/
143  public function load_from_db( $in_db_result
144  ) {
145  $ret = parent::load_from_db($in_db_result);
146 
147  $this->class_description = "This is a 'Collection' Class for Users.";
148 
149  $this->_set_up_container();
150  }
151 
152  /***********************/
160  public function get_login_instance() {
161  if (!($this->_login_object instanceof CO_Security_Login)) {
162  $this->_load_login();
163  }
164 
165  return $this->_login_object;
166  }
167 
168  /***********************/
174  public function has_login() {
175  return (intval($this->tags()[0]) > 0);
176  }
177 
178  /***********************/
184  public function has_login_i_cant_see() {
185  $this->get_login_instance();
186  return (!($this->_login_object instanceof CO_Security_Login) && (isset($this->tags()[0]) && intval($this->tags()[0])));
187  }
188 
189  /***********************/
195  public function is_god() {
196  $tags = $this->tags();
197 
198  return isset($tags) && is_array($tags) && count($tags) && (0 < intval($tags[0])) && (intval($tags[0]) == CO_Config::god_mode_id());
199  }
200 
201  /***********************/
205  public function is_manager() {
206  if (!$this->is_god() && !isset($this->_login_object)) {
207  $this->_load_login();
208  }
209 
210  return $this->is_god() || (isset($this->_login_object) && ($this->_login_object instanceof CO_Login_Manager));
211  }
212 
213  /***********************/
219  public function set_tags( $in_tags_array
220  ) {
221  $ret = false;
222 
223  if (isset($in_tags_array) && is_array($in_tags_array) && count($in_tags_array) && (11 > count($in_tags_array))) {
224  // We cannot assign a user we don't have write permissions for
225  $id_pool = $this->get_access_object()->get_security_ids();
226  $tag0 = intval($in_tags_array[0]);
227  if ($this->get_access_object()->god_mode() || ((isset($id_pool) && is_array($id_pool) && count($id_pool) && ((0 == $tag0) || in_array($tag0, $id_pool))))) {
228  $ret = parent::set_tags($in_tags_array);
229  }
230  }
231 
232  return $ret;
233  }
234 
235  /***********************/
241  public function set_tag( $in_tag_index,
242  $in_tag_value
243  ) {
244  $ret = false;
245 
246  $in_tag_index = intval($in_tag_index);
247 
248  if ((10 > $in_tag_index) && $this->user_can_write()) {
249  // We cannot assign a user we don't have write permissions for
250  $id_pool = $this->get_access_object()->get_security_ids();
251  if ($this->get_access_object()->god_mode() || ((isset($id_pool) && is_array($id_pool) && count($id_pool) && ((0 <= $in_tag_index) || in_array(intval($in_tag_value), $id_pool))))) {
252  $ret = parent::set_tag($in_tag_index, $in_tag_value);
253  }
254  }
255 
256  return $ret;
257  }
258 
259  /***********************/
265  public function get_surname() {
266  return isset($this->_tags[1]) ? $this->_tags[1] : '';
267  }
268 
269  /***********************/
275  public function set_surname( $in_surname
276  ) {
277  return $this->set_tag(1, $in_surname);
278  }
279 
280  /***********************/
286  public function get_middle_name() {
287  return isset($this->_tags[2]) ? $this->_tags[2] : '';
288  }
289 
290  /***********************/
296  public function set_middle_name( $in_middle_name
297  ) {
298  return $this->set_tag(2, $in_middle_name);
299  }
300 
301  /***********************/
307  public function get_given_name() {
308  return isset($this->_tags[3]) ? $this->_tags[3] : '';
309  }
310 
311  /***********************/
317  public function set_given_name( $in_given_name
318  ) {
319  return $this->set_tag(3, $in_given_name);
320  }
321 
322  /***********************/
328  public function get_prefix() {
329  return isset($this->_tags[4]) ? $this->_tags[4] : '';
330  }
331 
332  /***********************/
338  public function set_prefix( $in_prefix
339  ) {
340  return $this->set_tag(4, $in_prefix);
341  }
342 
343  /***********************/
349  public function get_suffix() {
350  return isset($this->_tags[5]) ? $this->_tags[5] : '';
351  }
352 
353  /***********************/
359  public function set_suffix( $in_suffix
360  ) {
361  return $this->set_tag(5, $in_suffix);
362  }
363 
364  /***********************/
370  public function get_nickname() {
371  return isset($this->_tags[6]) ? $this->_tags[6] : '';
372  }
373 
374  /***********************/
380  public function set_nickname( $in_nickname
381  ) {
382  return $this->set_tag(6, $in_nickname);
383  }
384 
385  /***********************/
394  public function set_login( $in_login_id_integer
395  ) {
396  $ret = parent::user_can_write();
397  $in_login_id_integer = intval($in_login_id_integer);
398  // Further check to make sure that the current login is a manager.
399  if ($ret && ($this->get_access_object()->god_mode() || ($this->get_access_object()->get_login_item() instanceof CO_Login_Manager))) {
400  $login_item = $this->get_access_object()->get_login_item($in_login_id_integer);
401 
402  if ((0 == $in_login_id_integer) || ($login_item instanceof CO_Security_Login)) {
403  $tag0 = (0 == $in_login_id_integer) ? NULL : strval(intval($in_login_id_integer));
404 
405  $ret = $this->set_tag(0, $tag0);
406 
407  if ($ret) { // Make sure that we'll get a fresh login next time.
408  $this->_login_object = NULL;
409  }
410  }
411  } else {
415  __FILE__,
416  __LINE__,
417  __METHOD__
418  );
419  }
420 
421  return $ret;
422  }
423 
424  /***********************/
430  public function get_lang() {
431  $ret = parent::get_lang();
432 
433  if (!isset($this->context['lang'])) {
434  $login_object = $this->get_login_instance();
435  if (isset($login_object) && ($login_object instanceof CO_Security_Login)) {
436  $ret = $login_object->get_lang();
437  }
438  }
439 
440  return $ret;
441  }
442 
443  /***********************/
449  public function delete_from_db( $with_extreme_prejudice = false,
450  $delete_login_object_too = false
451  ) {
452  if ($with_extreme_prejudice && $this->user_can_write()) {
453  // We don't error-check this on purpose, as it's a given that there might be issues, here. This is a "due dilligence" thing.
454  $user_items_to_delete = $this->children();
455 
456  foreach ($user_items_to_delete as $child) {
457  if ($child->user_can_write()) {
458  $child->delete_from_db();
459  }
460  }
461  }
462 
463  // Again, we won't return false if this fails, but we will fetch the error.
464  if ($delete_login_object_too) {
465  $login_object = $this->get_login_instance();
466 
467  if (isset($login_object) && $login_object->user_can_write()) {
468  $login_object->delete_from_db();
469  $this->error = $login_object->error;
470  }
471  }
472 
473  return parent::delete_from_db();
474  }
475 };
if(!defined( 'LGV_LANG_CATCHER'))
global $g_lang_override
if(isset($g_lang_override) && $g_lang_override &&file_exists(CO_Config::lang_class_dir().'/'. $g_lang_override.'.php')) $lang_file
$_login_object
The Security DB COBRA login instance associated with this user.
set_login( $in_login_id_integer)
set_middle_name( $in_middle_name)
set_tag( $in_tag_index, $in_tag_value)
__construct( $in_db_object=NULL, $in_db_result=NULL, $in_owner_id=NULL, $in_tags_array=NULL)
count( $is_recursive=false)
static $user_error_code_invalid_class
Definition: common.inc.php:67
static $user_error_code_invalid_id
Definition: common.inc.php:66
static $user_error_code_user_not_authorized
Definition: common.inc.php:65
static $user_error_name_invalid_class
Definition: en.php:59
static $user_error_name_user_not_authorized
Definition: en.php:55
static $user_error_name_invalid_id
Definition: en.php:57
static $user_error_desc_invalid_id
Definition: en.php:58
static $user_error_desc_invalid_class
Definition: en.php:60
static $user_error_desc_user_not_authorized
Definition: en.php:56
This class provides a general error report, with file, method and error information.
Definition: error.class.php:32