4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2014
40 class CRM_Utils_Recent
{
43 * max number of items in queue
47 CONST MAX_ITEMS
= 10, STORE_NAME
= 'CRM_Utils_Recent';
50 * The list of recently viewed items
55 static private $_recent = NULL;
58 * initialize this class and set the static variables
64 static function initialize() {
65 if (!self
::$_recent) {
66 $session = CRM_Core_Session
::singleton();
67 self
::$_recent = $session->get(self
::STORE_NAME
);
68 if (!self
::$_recent) {
69 self
::$_recent = array();
75 * return the recently viewed array
77 * @return array the recently viewed array
81 static function &get() {
83 return self
::$_recent;
87 * add an item to the recent stack
89 * @param string $title the title to display
90 * @param string $url the link for the above title
91 * @param string $id object id
96 * @param array $others
98 * @internal param string $icon a link to a graphical image
103 static function add($title,
112 $session = CRM_Core_Session
::singleton();
114 // make sure item is not already present in list
115 for ($i = 0; $i < count(self
::$_recent); $i++
) {
116 if (self
::$_recent[$i]['url'] == $url) {
117 // delete item from array
118 array_splice(self
::$_recent, $i, 1);
123 if (!is_array($others)) {
127 array_unshift(self
::$_recent,
133 'contact_id' => $contactId,
134 'contactName' => $contactName,
135 'subtype' => CRM_Utils_Array
::value('subtype', $others),
136 'isDeleted' => CRM_Utils_Array
::value('isDeleted', $others, FALSE),
137 'image_url' => CRM_Utils_Array
::value('imageUrl', $others),
138 'edit_url' => CRM_Utils_Array
::value('editUrl', $others),
139 'delete_url' => CRM_Utils_Array
::value('deleteUrl', $others),
142 if (count(self
::$_recent) > self
::MAX_ITEMS
) {
143 array_pop(self
::$_recent);
146 CRM_Utils_Hook
::recent(self
::$_recent);
148 $session->set(self
::STORE_NAME
, self
::$_recent);
152 * delete an item from the recent stack
154 * @param array $recentItem array of the recent Item to be removed
160 static function del($recentItem) {
162 $tempRecent = self
::$_recent;
166 // make sure item is not already present in list
167 for ($i = 0; $i < count($tempRecent); $i++
) {
168 if (!($tempRecent[$i]['id'] == $recentItem['id'] &&
169 $tempRecent[$i]['type'] == $recentItem['type']
171 self
::$_recent[] = $tempRecent[$i];
175 $session = CRM_Core_Session
::singleton();
176 $session->set(self
::STORE_NAME
, self
::$_recent);
180 * delete an item from the recent stack
182 * @param string $id contact id that had to be removed
188 static function delContact($id) {
191 $tempRecent = self
::$_recent;
196 for ($i = 0; $i < count($tempRecent); $i++
) {
197 // don't include deleted contact in recent.
198 if (CRM_Utils_Array
::value('contact_id', $tempRecent[$i]) == $id) {
201 self
::$_recent[] = $tempRecent[$i];
204 $session = CRM_Core_Session
::singleton();
205 $session->set(self
::STORE_NAME
, self
::$_recent);