3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2015
34 * Recent items utility class.
36 class CRM_Utils_Recent
{
39 * Max number of items in queue.
43 const MAX_ITEMS
= 10, STORE_NAME
= 'CRM_Utils_Recent';
46 * The list of recently viewed items.
50 static private $_recent = NULL;
53 * Initialize this class and set the static variables.
55 public static function initialize() {
56 if (!self
::$_recent) {
57 $session = CRM_Core_Session
::singleton();
58 self
::$_recent = $session->get(self
::STORE_NAME
);
59 if (!self
::$_recent) {
60 self
::$_recent = array();
66 * Return the recently viewed array.
69 * the recently viewed array
71 public static function &get() {
73 return self
::$_recent;
77 * Add an item to the recent stack.
79 * @param string $title
80 * The title to display.
82 * The link for the above title.
86 * @param int $contactId
87 * @param string $contactName
88 * @param array $others
90 public static function add(
100 $session = CRM_Core_Session
::singleton();
102 // make sure item is not already present in list
103 for ($i = 0; $i < count(self
::$_recent); $i++
) {
104 if (self
::$_recent[$i]['url'] == $url) {
105 // delete item from array
106 array_splice(self
::$_recent, $i, 1);
111 if (!is_array($others)) {
115 array_unshift(self
::$_recent,
121 'contact_id' => $contactId,
122 'contactName' => $contactName,
123 'subtype' => CRM_Utils_Array
::value('subtype', $others),
124 'isDeleted' => CRM_Utils_Array
::value('isDeleted', $others, FALSE),
125 'image_url' => CRM_Utils_Array
::value('imageUrl', $others),
126 'edit_url' => CRM_Utils_Array
::value('editUrl', $others),
127 'delete_url' => CRM_Utils_Array
::value('deleteUrl', $others),
130 if (count(self
::$_recent) > self
::MAX_ITEMS
) {
131 array_pop(self
::$_recent);
134 CRM_Utils_Hook
::recent(self
::$_recent);
136 $session->set(self
::STORE_NAME
, self
::$_recent);
140 * Delete an item from the recent stack.
142 * @param array $recentItem
143 * Array of the recent Item to be removed.
145 public static function del($recentItem) {
147 $tempRecent = self
::$_recent;
151 // make sure item is not already present in list
152 for ($i = 0; $i < count($tempRecent); $i++
) {
153 if (!($tempRecent[$i]['id'] == $recentItem['id'] &&
154 $tempRecent[$i]['type'] == $recentItem['type']
157 self
::$_recent[] = $tempRecent[$i];
161 $session = CRM_Core_Session
::singleton();
162 $session->set(self
::STORE_NAME
, self
::$_recent);
166 * Delete an item from the recent stack.
169 * Contact id that had to be removed.
171 public static function delContact($id) {
174 $tempRecent = self
::$_recent;
179 for ($i = 0; $i < count($tempRecent); $i++
) {
180 // don't include deleted contact in recent.
181 if (CRM_Utils_Array
::value('contact_id', $tempRecent[$i]) == $id) {
184 self
::$_recent[] = $tempRecent[$i];
187 $session = CRM_Core_Session
::singleton();
188 $session->set(self
::STORE_NAME
, self
::$_recent);