3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
39 class CRM_Utils_Recent
{
42 * Max number of items in queue.
46 const MAX_ITEMS
= 10, STORE_NAME
= 'CRM_Utils_Recent';
49 * The list of recently viewed items.
53 static private $_recent = NULL;
56 * Initialize this class and set the static variables.
60 public static function initialize() {
61 if (!self
::$_recent) {
62 $session = CRM_Core_Session
::singleton();
63 self
::$_recent = $session->get(self
::STORE_NAME
);
64 if (!self
::$_recent) {
65 self
::$_recent = array();
71 * Return the recently viewed array.
74 * the recently viewed array
76 public static function &get() {
78 return self
::$_recent;
82 * Add an item to the recent stack.
84 * @param string $title
85 * The title to display.
87 * The link for the above title.
91 * @param int $contactId
92 * @param string $contactName
93 * @param array $others
97 public static function add(
107 $session = CRM_Core_Session
::singleton();
109 // make sure item is not already present in list
110 for ($i = 0; $i < count(self
::$_recent); $i++
) {
111 if (self
::$_recent[$i]['url'] == $url) {
112 // delete item from array
113 array_splice(self
::$_recent, $i, 1);
118 if (!is_array($others)) {
122 array_unshift(self
::$_recent,
128 'contact_id' => $contactId,
129 'contactName' => $contactName,
130 'subtype' => CRM_Utils_Array
::value('subtype', $others),
131 'isDeleted' => CRM_Utils_Array
::value('isDeleted', $others, FALSE),
132 'image_url' => CRM_Utils_Array
::value('imageUrl', $others),
133 'edit_url' => CRM_Utils_Array
::value('editUrl', $others),
134 'delete_url' => CRM_Utils_Array
::value('deleteUrl', $others),
137 if (count(self
::$_recent) > self
::MAX_ITEMS
) {
138 array_pop(self
::$_recent);
141 CRM_Utils_Hook
::recent(self
::$_recent);
143 $session->set(self
::STORE_NAME
, self
::$_recent);
147 * Delete an item from the recent stack.
149 * @param array $recentItem
150 * Array of the recent Item to be removed.
154 public static function del($recentItem) {
156 $tempRecent = self
::$_recent;
160 // make sure item is not already present in list
161 for ($i = 0; $i < count($tempRecent); $i++
) {
162 if (!($tempRecent[$i]['id'] == $recentItem['id'] &&
163 $tempRecent[$i]['type'] == $recentItem['type']
166 self
::$_recent[] = $tempRecent[$i];
170 $session = CRM_Core_Session
::singleton();
171 $session->set(self
::STORE_NAME
, self
::$_recent);
175 * Delete an item from the recent stack.
178 * Contact id that had to be removed.
182 public static function delContact($id) {
185 $tempRecent = self
::$_recent;
190 for ($i = 0; $i < count($tempRecent); $i++
) {
191 // don't include deleted contact in recent.
192 if (CRM_Utils_Array
::value('contact_id', $tempRecent[$i]) == $id) {
195 self
::$_recent[] = $tempRecent[$i];
198 $session = CRM_Core_Session
::singleton();
199 $session->set(self
::STORE_NAME
, self
::$_recent);