5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
33 * @copyright CiviCRM LLC (c) 2004-2013
41 class CRM_Utils_Recent
{
44 * max number of items in queue
48 CONST MAX_ITEMS
= 10, STORE_NAME
= 'CRM_Utils_Recent';
51 * The list of recently viewed items
56 static private $_recent = NULL;
59 * initialize this class and set the static variables
65 static function initialize() {
66 if (!self
::$_recent) {
67 $session = CRM_Core_Session
::singleton();
68 self
::$_recent = $session->get(self
::STORE_NAME
);
69 if (!self
::$_recent) {
70 self
::$_recent = array();
76 * return the recently viewed array
78 * @return array the recently viewed array
82 static function &get() {
84 return self
::$_recent;
88 * add an item to the recent stack
90 * @param string $title the title to display
91 * @param string $url the link for the above title
92 * @param string $icon a link to a graphical image
93 * @param string $id object id
99 static function add($title,
108 $session = CRM_Core_Session
::singleton();
110 // make sure item is not already present in list
111 for ($i = 0; $i < count(self
::$_recent); $i++
) {
112 if (self
::$_recent[$i]['url'] == $url) {
113 // delete item from array
114 array_splice(self
::$_recent, $i, 1);
119 if (!is_array($others)) {
123 array_unshift(self
::$_recent,
129 'contact_id' => $contactId,
130 'contactName' => $contactName,
131 'subtype' => CRM_Utils_Array
::value('subtype', $others),
132 'isDeleted' => CRM_Utils_Array
::value('isDeleted', $others, FALSE),
133 'image_url' => CRM_Utils_Array
::value('imageUrl', $others),
134 'edit_url' => CRM_Utils_Array
::value('editUrl', $others),
135 'delete_url' => CRM_Utils_Array
::value('deleteUrl', $others),
138 if (count(self
::$_recent) > self
::MAX_ITEMS
) {
139 array_pop(self
::$_recent);
142 CRM_Utils_Hook
::recent(self
::$_recent);
144 $session->set(self
::STORE_NAME
, self
::$_recent);
148 * delete an item from the recent stack
150 * @param array $recentItem array of the recent Item to be removed
156 static function del($recentItem) {
158 $tempRecent = self
::$_recent;
162 // make sure item is not already present in list
163 for ($i = 0; $i < count($tempRecent); $i++
) {
164 if (!($tempRecent[$i]['id'] == $recentItem['id'] &&
165 $tempRecent[$i]['type'] == $recentItem['type']
167 self
::$_recent[] = $tempRecent[$i];
171 $session = CRM_Core_Session
::singleton();
172 $session->set(self
::STORE_NAME
, self
::$_recent);
176 * delete an item from the recent stack
178 * @param string $id contact id that had to be removed
184 static function delContact($id) {
187 $tempRecent = self
::$_recent;
192 for ($i = 0; $i < count($tempRecent); $i++
) {
193 // don't include deleted contact in recent.
194 if (CRM_Utils_Array
::value('contact_id', $tempRecent[$i]) == $id) {
197 self
::$_recent[] = $tempRecent[$i];
200 $session = CRM_Core_Session
::singleton();
201 $session->set(self
::STORE_NAME
, self
::$_recent);