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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 * Recent items utility class.
37 class CRM_Utils_Recent
{
40 * Max number of items in queue.
44 const MAX_ITEMS
= 10, STORE_NAME
= 'CRM_Utils_Recent';
47 * The list of recently viewed items.
51 static private $_recent = NULL;
54 * Initialize this class and set the static variables.
56 public static function initialize() {
57 if (!self
::$_recent) {
58 $session = CRM_Core_Session
::singleton();
59 self
::$_recent = $session->get(self
::STORE_NAME
);
60 if (!self
::$_recent) {
61 self
::$_recent = array();
67 * Return the recently viewed array.
70 * the recently viewed array
72 public static function &get() {
74 return self
::$_recent;
78 * Add an item to the recent stack.
80 * @param string $title
81 * The title to display.
83 * The link for the above title.
87 * @param int $contactId
88 * @param string $contactName
89 * @param array $others
91 public static function add(
101 $session = CRM_Core_Session
::singleton();
103 // make sure item is not already present in list
104 for ($i = 0; $i < count(self
::$_recent); $i++
) {
105 if (self
::$_recent[$i]['url'] == $url) {
106 // delete item from array
107 array_splice(self
::$_recent, $i, 1);
112 if (!is_array($others)) {
116 array_unshift(self
::$_recent,
122 'contact_id' => $contactId,
123 'contactName' => $contactName,
124 'subtype' => CRM_Utils_Array
::value('subtype', $others),
125 'isDeleted' => CRM_Utils_Array
::value('isDeleted', $others, FALSE),
126 'image_url' => CRM_Utils_Array
::value('imageUrl', $others),
127 'edit_url' => CRM_Utils_Array
::value('editUrl', $others),
128 'delete_url' => CRM_Utils_Array
::value('deleteUrl', $others),
131 if (count(self
::$_recent) > self
::MAX_ITEMS
) {
132 array_pop(self
::$_recent);
135 CRM_Utils_Hook
::recent(self
::$_recent);
137 $session->set(self
::STORE_NAME
, self
::$_recent);
141 * Delete an item from the recent stack.
143 * @param array $recentItem
144 * Array of the recent Item to be removed.
146 public static function del($recentItem) {
148 $tempRecent = self
::$_recent;
152 // make sure item is not already present in list
153 for ($i = 0; $i < count($tempRecent); $i++
) {
154 if (!($tempRecent[$i]['id'] == $recentItem['id'] &&
155 $tempRecent[$i]['type'] == $recentItem['type']
158 self
::$_recent[] = $tempRecent[$i];
162 $session = CRM_Core_Session
::singleton();
163 $session->set(self
::STORE_NAME
, self
::$_recent);
167 * Delete an item from the recent stack.
170 * Contact id that had to be removed.
172 public static function delContact($id) {
175 $tempRecent = self
::$_recent;
180 for ($i = 0; $i < count($tempRecent); $i++
) {
181 // don't include deleted contact in recent.
182 if (CRM_Utils_Array
::value('contact_id', $tempRecent[$i]) == $id) {
185 self
::$_recent[] = $tempRecent[$i];
188 $session = CRM_Core_Session
::singleton();
189 $session->set(self
::STORE_NAME
, self
::$_recent);