ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilUserClipboard.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
12{
13 const SESSION_KEYWORD = 'usr_clipboard';
14
15 private static $instance = null;
16
17 private $user_id = 0;
18 private $clipboard = array();
19
20
24 protected function __construct($a_user_id)
25 {
26 $this->user_id = $a_user_id;
27 $this->read();
28 }
29
35 public static function getInstance($a_usr_id)
36 {
37 if (!self::$instance) {
38 self::$instance = new self($a_usr_id);
39 }
40 return self::$instance;
41 }
42
47 public function hasContent()
48 {
49 return (bool) count($this->clipboard);
50 }
51
56 public function get()
57 {
58 return (array) $this->clipboard;
59 }
60
65 public function getValidatedContent()
66 {
67 $valid = array();
68 foreach ($this->clipboard as $usr_id) {
69 include_once './Services/User/classes/class.ilObjUser.php';
70 if (strlen(ilObjUser::_lookupLogin($usr_id))) {
71 $valid[] = $usr_id;
72 }
73 }
74 return $valid;
75 }
76
80 public function add($a_usr_ids)
81 {
82 $this->clipboard = array_unique(array_merge($this->clipboard, (array) $a_usr_ids));
83 }
84
89 public function delete(array $a_usr_ids)
90 {
91 $remaining = array();
92 foreach ($this->get() as $usr_id) {
93 if (!in_array($usr_id, $a_usr_ids)) {
94 $remaining[] = $usr_id;
95 }
96 }
97 $this->replace($remaining);
98 }
99
104 public function replace(array $a_usr_ids)
105 {
106 $this->clipboard = $a_usr_ids;
107 }
108
109 public function clear()
110 {
111 $this->clipboard = array();
112 }
113
117 public function save()
118 {
119 ilSession::set(self::SESSION_KEYWORD, (array) $this->clipboard);
120 }
121
125 protected function read()
126 {
127 $this->clipboard = (array) ilSession::get(self::SESSION_KEYWORD);
128 }
129}
An exception for terminatinating execution or to throw for unit testing.
static _lookupLogin($a_user_id)
lookup login
static set($a_var, $a_val)
Set a value.
static get($a_var)
Get a value.
save()
Save clipboard content in session.
replace(array $a_usr_ids)
Replace clipboard content.
hasContent()
Check if clipboard has content.
static getInstance($a_usr_id)
Get singelton instance.
add($a_usr_ids)
Add entries to clipboard.
getValidatedContent()
Get validated content of clipboard.
__construct($a_user_id)
singleton constructor
read()
Read from session.
$valid
if($state['core:TerminatedAssocId'] !==null) $remaining