Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Class contains Contact dashboard related functions | |
38 | */ | |
39 | class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { | |
3cfa8e5e | 40 | /** |
fe482240 | 41 | * Add Dashboard. |
3cfa8e5e | 42 | * |
6a0b768e TO |
43 | * @param array $params |
44 | * Values. | |
3cfa8e5e | 45 | * |
3cfa8e5e EM |
46 | * |
47 | * @return object | |
48 | */ | |
00be9182 | 49 | public static function create($params) { |
3cfa8e5e EM |
50 | $hook = empty($params['id']) ? 'create' : 'edit'; |
51 | CRM_Utils_Hook::pre($hook, 'Dashboard', CRM_Utils_Array::value('id', $params), $params); | |
52 | $dao = self::addDashlet($params); | |
53 | CRM_Utils_Hook::post($hook, 'Dashboard', $dao->id, $dao); | |
54 | return $dao; | |
55 | } | |
6a488035 TO |
56 | |
57 | /** | |
fe482240 | 58 | * Get the list of dashlets enabled by admin. |
6a488035 | 59 | * |
6a0b768e TO |
60 | * @param bool $all |
61 | * All or only active. | |
62 | * @param bool $checkPermission | |
63 | * All or only authorized for the current user. | |
6a488035 | 64 | * |
a6c01b45 CW |
65 | * @return array |
66 | * array of dashlets | |
6a488035 | 67 | */ |
00be9182 | 68 | public static function getDashlets($all = TRUE, $checkPermission = TRUE) { |
6a488035 TO |
69 | $dashlets = array(); |
70 | $dao = new CRM_Core_DAO_Dashboard(); | |
71 | ||
72 | if (!$all) { | |
73 | $dao->is_active = 1; | |
74 | } | |
75 | ||
76 | $dao->domain_id = CRM_Core_Config::domainID(); | |
77 | ||
78 | $dao->find(); | |
79 | while ($dao->fetch()) { | |
ee117e9c | 80 | if ($checkPermission && !self::checkPermission($dao->permission, $dao->permission_operator)) { |
6a488035 TO |
81 | continue; |
82 | } | |
83 | ||
84 | $values = array(); | |
85 | CRM_Core_DAO::storeValues($dao, $values); | |
86 | $dashlets[$dao->id] = $values; | |
87 | } | |
88 | ||
89 | return $dashlets; | |
90 | } | |
91 | ||
92 | /** | |
08727453 | 93 | * Get the list of dashlets for the current user or the specified user. |
6a488035 | 94 | * |
5aa910d4 JM |
95 | * Additionlly, initializes the dashboard with defaults if this is the |
96 | * user's first visit to their dashboard. | |
6a488035 | 97 | * |
6a0b768e TO |
98 | * @param bool $flatFormat |
99 | * This is true if you want simple associated. | |
16b10e64 | 100 | * array of all the contact's dashlets whether or not they are enabled. |
6a488035 | 101 | * |
6a0b768e TO |
102 | * @param int $contactID |
103 | * Provide the dashlets for the contact id. | |
16b10e64 | 104 | * passed rather than the current user. |
77b97be7 | 105 | * |
a6c01b45 CW |
106 | * @return array |
107 | * array of dashlets | |
6a488035 | 108 | */ |
00be9182 | 109 | public static function getContactDashlets($flatFormat = FALSE, $contactID = NULL) { |
6a488035 TO |
110 | $dashlets = array(); |
111 | ||
15d9b3ae N |
112 | if (!$contactID) { |
113 | $contactID = CRM_Core_Session::singleton()->get('userID'); | |
114 | } | |
6a488035 | 115 | |
5aa910d4 | 116 | // Get contact dashboard dashlets. |
6a488035 TO |
117 | $hasDashlets = FALSE; |
118 | $dao = new CRM_Contact_DAO_DashboardContact(); | |
119 | $dao->contact_id = $contactID; | |
120 | $dao->orderBy('column_no asc, weight asc'); | |
121 | $dao->find(); | |
122 | while ($dao->fetch()) { | |
5aa910d4 JM |
123 | // When a dashlet is removed, it stays in the table with status disabled, |
124 | // so even if a user decides not to have any dashlets show, they will still | |
125 | // have records in the table to indicate that we are not newly initializing. | |
6a488035 TO |
126 | $hasDashlets = TRUE; |
127 | if (!$flatFormat) { | |
128 | if ($dao->is_active) { | |
129 | // append weight so that order is preserved. | |
130 | $dashlets[$dao->column_no]["{$dao->weight}-{$dao->dashboard_id}"] = $dao->is_minimized; | |
131 | } | |
132 | } | |
133 | else { | |
134 | $dashlets[$dao->dashboard_id] = $dao->dashboard_id; | |
135 | } | |
136 | } | |
137 | ||
138 | if ($flatFormat) { | |
139 | return $dashlets; | |
140 | } | |
141 | ||
5aa910d4 | 142 | // If empty, then initialize contact dashboard for this user. |
08727453 | 143 | if (!$hasDashlets) { |
98662f1c | 144 | return self::initializeDashlets($flatFormat); |
5aa910d4 JM |
145 | } |
146 | return $dashlets; | |
15d9b3ae N |
147 | } |
148 | ||
b5c2afd0 | 149 | /** |
fe482240 | 150 | * Setup default dashlets for new users. |
b5c2afd0 | 151 | * |
5aa910d4 JM |
152 | * When a user accesses their dashboard for the first time, set up |
153 | * the default dashlets. | |
154 | * | |
a6c01b45 | 155 | * @return array |
16b10e64 | 156 | * Array of dashboard_id's |
b5c2afd0 | 157 | */ |
98662f1c | 158 | public static function initializeDashlets($flatFormat = FALSE) { |
5aa910d4 | 159 | $dashlets = array(); |
353ffa53 TO |
160 | $getDashlets = civicrm_api3("Dashboard", "get", array( |
161 | 'domain_id' => CRM_Core_Config::domainID(), | |
408b79bf | 162 | 'option.limit' => 0, |
353ffa53 | 163 | )); |
15d9b3ae | 164 | $contactID = CRM_Core_Session::singleton()->get('userID'); |
15d9b3ae N |
165 | $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']); |
166 | $defaultDashlets = array(); | |
5aa910d4 | 167 | if (CRM_Utils_Array::value('blog', $allDashlets)) { |
15d9b3ae N |
168 | $defaultDashlets['blog'] = array( |
169 | 'dashboard_id' => $allDashlets['blog']['id'], | |
170 | 'is_active' => 1, | |
171 | 'column_no' => 1, | |
172 | 'contact_id' => $contactID, | |
15d9b3ae N |
173 | ); |
174 | } | |
175 | CRM_Utils_Hook::dashboard_defaults($allDashlets, $defaultDashlets); | |
176 | if (is_array($defaultDashlets) && !empty($defaultDashlets)) { | |
5aa910d4 JM |
177 | foreach ($defaultDashlets as $id => $defaultDashlet) { |
178 | $dashboard_id = $defaultDashlet['dashboard_id']; | |
179 | if (!self::checkPermission($getDashlets['values'][$dashboard_id]['permission'], | |
353ffa53 TO |
180 | $getDashlets['values'][$dashboard_id]['permission_operator']) |
181 | ) { | |
15d9b3ae N |
182 | continue; |
183 | } | |
184 | else { | |
185 | $assignDashlets = civicrm_api3("dashboard_contact", "create", $defaultDashlet); | |
98662f1c | 186 | if (!$flatFormat) { |
187 | $values = $assignDashlets['values'][$assignDashlets['id']]; | |
7dd6f516 | 188 | $dashlets[$values['column_no']][$values['weight'] - $values['dashboard_id']] = $values['is_minimized']; |
98662f1c | 189 | } |
190 | else { | |
191 | $dashlets[$dashboard_id] = $defaultDashlet['dashboard_id']; | |
192 | } | |
6a488035 | 193 | } |
6a488035 TO |
194 | } |
195 | } | |
5aa910d4 | 196 | return $dashlets; |
6a488035 | 197 | } |
08727453 | 198 | |
6a488035 TO |
199 | |
200 | /** | |
fe482240 | 201 | * Check dashlet permission for current user. |
6a488035 | 202 | * |
6a0b768e TO |
203 | * @param string $permission |
204 | * Comma separated list. | |
c490a46a | 205 | * @param string $operator |
6a488035 | 206 | * |
408b79bf | 207 | * @return bool |
a6c01b45 | 208 | * true if use has permission else false |
6a488035 | 209 | */ |
00be9182 | 210 | public static function checkPermission($permission, $operator) { |
6a488035 TO |
211 | if ($permission) { |
212 | $permissions = explode(',', $permission); | |
213 | $config = CRM_Core_Config::singleton(); | |
214 | ||
215 | static $allComponents; | |
216 | if (!$allComponents) { | |
217 | $allComponents = CRM_Core_Component::getNames(); | |
218 | } | |
219 | ||
220 | $hasPermission = FALSE; | |
221 | foreach ($permissions as $key) { | |
222 | $showDashlet = TRUE; | |
223 | ||
224 | $componentName = NULL; | |
225 | if (strpos($key, 'access') === 0) { | |
226 | $componentName = trim(substr($key, 6)); | |
227 | if (!in_array($componentName, $allComponents)) { | |
228 | $componentName = NULL; | |
229 | } | |
230 | } | |
231 | ||
232 | // hack to handle case permissions | |
233 | if (!$componentName && in_array($key, array( | |
353ffa53 | 234 | 'access my cases and activities', |
408b79bf | 235 | 'access all cases and activities', |
353ffa53 TO |
236 | )) |
237 | ) { | |
6a488035 TO |
238 | $componentName = 'CiviCase'; |
239 | } | |
240 | ||
241 | //hack to determine if it's a component related permission | |
242 | if ($componentName) { | |
243 | if (!in_array($componentName, $config->enableComponents) || | |
244 | !CRM_Core_Permission::check($key) | |
245 | ) { | |
246 | $showDashlet = FALSE; | |
247 | if ($operator == 'AND') { | |
248 | return $showDashlet; | |
249 | } | |
250 | } | |
251 | else { | |
252 | $hasPermission = TRUE; | |
253 | } | |
254 | } | |
255 | elseif (!CRM_Core_Permission::check($key)) { | |
256 | $showDashlet = FALSE; | |
257 | if ($operator == 'AND') { | |
258 | return $showDashlet; | |
259 | } | |
260 | } | |
261 | else { | |
262 | $hasPermission = TRUE; | |
263 | } | |
264 | } | |
265 | ||
266 | if (!$showDashlet && !$hasPermission) { | |
267 | return FALSE; | |
268 | } | |
269 | else { | |
270 | return TRUE; | |
271 | } | |
272 | } | |
273 | else { | |
274 | // if permission is not set consider everyone has permission to access it. | |
275 | return TRUE; | |
276 | } | |
277 | } | |
278 | ||
279 | /** | |
fe482240 | 280 | * Get details of each dashlets. |
6a488035 | 281 | * |
6a0b768e TO |
282 | * @param int $dashletID |
283 | * Widget ID. | |
6a488035 | 284 | * |
a6c01b45 CW |
285 | * @return array |
286 | * associted array title and content | |
6a488035 | 287 | */ |
00be9182 | 288 | public static function getDashletInfo($dashletID) { |
6a488035 TO |
289 | $dashletInfo = array(); |
290 | ||
291 | $params = array(1 => array($dashletID, 'Integer')); | |
15d9b3ae | 292 | $query = "SELECT name, label, url, fullscreen_url, is_fullscreen FROM civicrm_dashboard WHERE id = %1"; |
6a488035 TO |
293 | $dashboadDAO = CRM_Core_DAO::executeQuery($query, $params); |
294 | $dashboadDAO->fetch(); | |
295 | ||
296 | // build the content | |
297 | $dao = new CRM_Contact_DAO_DashboardContact(); | |
298 | ||
353ffa53 TO |
299 | $session = CRM_Core_Session::singleton(); |
300 | $dao->contact_id = $session->get('userID'); | |
6a488035 TO |
301 | $dao->dashboard_id = $dashletID; |
302 | $dao->find(TRUE); | |
303 | ||
304 | //reset content based on the cache time set in config | |
305 | $createdDate = strtotime($dao->created_date); | |
306 | $dateDiff = round(abs(time() - $createdDate) / 60); | |
307 | ||
308 | $config = CRM_Core_Config::singleton(); | |
309 | if ($config->dashboardCacheTimeout <= $dateDiff) { | |
310 | $dao->content = NULL; | |
311 | } | |
312 | ||
313 | // if content is empty and url is set, retrieve it from url | |
314 | if (!$dao->content && $dashboadDAO->url) { | |
315 | $url = $dashboadDAO->url; | |
316 | ||
317 | // CRM-7087 | |
318 | // -lets use relative url for internal use. | |
319 | // -make sure relative url should not be htmlize. | |
320 | if (substr($dashboadDAO->url, 0, 4) != 'http') { | |
36ffcc5f | 321 | $urlParam = explode('?', $dashboadDAO->url); |
6a488035 TO |
322 | $url = CRM_Utils_System::url($urlParam[0], $urlParam[1], TRUE, NULL, FALSE); |
323 | } | |
324 | ||
325 | //get content from url | |
326 | $dao->content = CRM_Utils_System::getServerResponse($url); | |
327 | $dao->created_date = date("YmdHis"); | |
328 | $dao->save(); | |
329 | } | |
330 | ||
331 | $dashletInfo = array( | |
332 | 'title' => $dashboadDAO->label, | |
15d9b3ae | 333 | 'name' => $dashboadDAO->name, |
6a488035 TO |
334 | 'content' => $dao->content, |
335 | ); | |
336 | ||
337 | if ($dashboadDAO->is_fullscreen) { | |
338 | $fullscreenUrl = $dashboadDAO->fullscreen_url; | |
339 | if (substr($fullscreenUrl, 0, 4) != 'http') { | |
36ffcc5f | 340 | $urlParam = explode('?', $dashboadDAO->fullscreen_url); |
6a488035 TO |
341 | $fullscreenUrl = CRM_Utils_System::url($urlParam[0], $urlParam[1], TRUE, NULL, FALSE); |
342 | } | |
343 | $dashletInfo['fullscreenUrl'] = $fullscreenUrl; | |
344 | } | |
345 | return $dashletInfo; | |
346 | } | |
347 | ||
348 | /** | |
fe482240 | 349 | * Save changes made by use to the Dashlet. |
6a488035 | 350 | * |
6a0b768e | 351 | * @param array $columns |
6a488035 | 352 | * |
100fef9d | 353 | * @param int $contactID |
77b97be7 EM |
354 | * |
355 | * @throws RuntimeException | |
6a488035 | 356 | * @return void |
6a488035 | 357 | */ |
2aa397bc | 358 | public static function saveDashletChanges($columns, $contactID = NULL) { |
15d9b3ae N |
359 | $session = CRM_Core_Session::singleton(); |
360 | if (!$contactID) { | |
361 | $contactID = $session->get('userID'); | |
362 | } | |
363 | ||
f583d89b TO |
364 | if (empty($contactID)) { |
365 | throw new RuntimeException("Failed to determine contact ID"); | |
366 | } | |
6a488035 | 367 | |
dcf56200 | 368 | //we need to get existing dashlets, so we know when to update or insert |
15d9b3ae | 369 | $contactDashlets = self::getContactDashlets(TRUE, $contactID); |
6a488035 TO |
370 | |
371 | $dashletIDs = array(); | |
372 | if (is_array($columns)) { | |
373 | foreach ($columns as $colNo => $dashlets) { | |
408b79bf | 374 | if (!is_int($colNo)) { |
6a488035 TO |
375 | continue; |
376 | } | |
377 | $weight = 1; | |
378 | foreach ($dashlets as $dashletID => $isMinimized) { | |
379 | $isMinimized = (int) $isMinimized; | |
380 | if (in_array($dashletID, $contactDashlets)) { | |
381 | $query = " UPDATE civicrm_dashboard_contact | |
382 | SET weight = {$weight}, is_minimized = {$isMinimized}, column_no = {$colNo}, is_active = 1 | |
383 | WHERE dashboard_id = {$dashletID} AND contact_id = {$contactID} "; | |
384 | } | |
385 | else { | |
386 | $query = " INSERT INTO civicrm_dashboard_contact | |
387 | ( weight, is_minimized, column_no, is_active, dashboard_id, contact_id ) | |
388 | VALUES( {$weight}, {$isMinimized}, {$colNo}, 1, {$dashletID}, {$contactID} )"; | |
389 | } | |
390 | // fire update query for each column | |
391 | $dao = CRM_Core_DAO::executeQuery($query); | |
392 | ||
393 | $dashletIDs[] = $dashletID; | |
394 | $weight++; | |
395 | } | |
396 | } | |
397 | } | |
398 | ||
399 | if (!empty($dashletIDs)) { | |
400 | // we need to disable widget that removed | |
401 | $updateQuery = " UPDATE civicrm_dashboard_contact | |
402 | SET is_active = 0 | |
403 | WHERE dashboard_id NOT IN ( " . implode(',', $dashletIDs) . ") AND contact_id = {$contactID}"; | |
404 | } | |
405 | else { | |
406 | // this means all widgets are disabled | |
407 | $updateQuery = " UPDATE civicrm_dashboard_contact | |
408 | SET is_active = 0 | |
409 | WHERE contact_id = {$contactID}"; | |
410 | } | |
411 | ||
412 | CRM_Core_DAO::executeQuery($updateQuery); | |
413 | } | |
414 | ||
415 | /** | |
fe482240 | 416 | * Add dashlets. |
6a488035 | 417 | * |
6a0b768e | 418 | * @param array $params |
6a488035 | 419 | * |
a6c01b45 CW |
420 | * @return object |
421 | * $dashlet returns dashlet object | |
6a488035 | 422 | */ |
00be9182 | 423 | public static function addDashlet(&$params) { |
6a488035 | 424 | |
32c93376 | 425 | // special case to handle duplicate entries for report instances |
15d9b3ae N |
426 | $dashboardID = CRM_Utils_Array::value('id', $params); |
427 | ||
a7488080 | 428 | if (!empty($params['instanceURL'])) { |
6a488035 TO |
429 | $query = "SELECT id |
430 | FROM `civicrm_dashboard` | |
431 | WHERE url LIKE '" . CRM_Utils_Array::value('instanceURL', $params) . "&%'"; | |
432 | $dashboardID = CRM_Core_DAO::singleValueQuery($query); | |
433 | } | |
434 | ||
435 | $dashlet = new CRM_Core_DAO_Dashboard(); | |
436 | ||
437 | if (!$dashboardID) { | |
438 | // check url is same as exiting entries, if yes just update existing | |
a7488080 | 439 | if (!empty($params['name'])) { |
15d9b3ae N |
440 | $dashlet->name = CRM_Utils_Array::value('name', $params); |
441 | $dashlet->find(TRUE); | |
442 | } | |
443 | else { | |
444 | $dashlet->url = CRM_Utils_Array::value('url', $params); | |
445 | $dashlet->find(TRUE); | |
446 | } | |
3cfa8e5e EM |
447 | if (empty($params['domain_id'])) { |
448 | $dashlet->domain_id = CRM_Core_Config::domainID(); | |
449 | } | |
6a488035 TO |
450 | } |
451 | else { | |
452 | $dashlet->id = $dashboardID; | |
453 | } | |
454 | ||
455 | if (is_array(CRM_Utils_Array::value('permission', $params))) { | |
456 | $params['permission'] = implode(',', $params['permission']); | |
457 | } | |
458 | $dashlet->copyValues($params); | |
6a488035 TO |
459 | $dashlet->save(); |
460 | ||
461 | // now we need to make dashlet entries for each contact | |
462 | self::addContactDashlet($dashlet); | |
463 | ||
464 | return $dashlet; | |
465 | } | |
466 | ||
b5c2afd0 EM |
467 | /** |
468 | * @param $url | |
469 | * | |
470 | * @return string | |
471 | */ | |
00be9182 | 472 | public static function getDashletName($url) { |
fa4916a4 | 473 | $urlElements = explode('/', $url); |
474 | if ($urlElements[1] == 'dashlet') { | |
475 | return $urlElements[2]; | |
476 | } | |
477 | elseif ($urlElements[1] == 'report') { | |
478 | return 'report/' . $urlElements[3]; | |
479 | } | |
480 | return $url; | |
481 | } | |
353ffa53 | 482 | |
6a488035 | 483 | /** |
fe482240 | 484 | * Update contact dashboard with new dashlet. |
6a488035 | 485 | * |
353ffa53 | 486 | * @param object : $dashlet |
6a488035 TO |
487 | * |
488 | * @return void | |
6a488035 | 489 | */ |
00be9182 | 490 | public static function addContactDashlet($dashlet) { |
6a488035 TO |
491 | $admin = CRM_Core_Permission::check('administer CiviCRM'); |
492 | ||
493 | // if dashlet is created by admin then you need to add it all contacts. | |
494 | // else just add to contact who is creating this dashlet | |
495 | $contactIDs = array(); | |
496 | if ($admin) { | |
497 | $query = "SELECT distinct( contact_id ) | |
498 | FROM civicrm_dashboard_contact | |
499 | WHERE contact_id NOT IN ( | |
500 | SELECT distinct( contact_id ) | |
501 | FROM civicrm_dashboard_contact WHERE dashboard_id = {$dashlet->id} | |
502 | )"; | |
503 | ||
504 | $dao = CRM_Core_DAO::executeQuery($query); | |
505 | while ($dao->fetch()) { | |
506 | $contactIDs[] = $dao->contact_id; | |
507 | } | |
508 | } | |
509 | else { | |
510 | //Get the id of Logged in User | |
511 | $session = CRM_Core_Session::singleton(); | |
155a0ed0 | 512 | $contactID = $session->get('userID'); |
22e263ad | 513 | if (!empty($contactID)) { |
155a0ed0 JM |
514 | $contactIDs[] = $session->get('userID'); |
515 | } | |
6a488035 TO |
516 | } |
517 | ||
518 | if (!empty($contactIDs)) { | |
519 | foreach ($contactIDs as $contactID) { | |
520 | $valuesArray[] = " ( {$dashlet->id}, {$contactID} )"; | |
521 | } | |
522 | ||
523 | $valuesString = implode(',', $valuesArray); | |
524 | $query = " | |
525 | INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id ) | |
526 | VALUES {$valuesString}"; | |
527 | ||
528 | CRM_Core_DAO::executeQuery($query); | |
529 | } | |
530 | } | |
531 | ||
dcf56200 | 532 | /** |
6a0b768e TO |
533 | * @param array $params |
534 | * Each item is a spec for a dashlet on the contact's dashboard. | |
dcf56200 TO |
535 | * @return bool |
536 | */ | |
00be9182 | 537 | public static function addContactDashletToDashboard(&$params) { |
15d9b3ae N |
538 | $valuesString = NULL; |
539 | $columns = array(); | |
540 | foreach ($params as $dashboardIDs) { | |
541 | $contactID = CRM_Utils_Array::value('contact_id', $dashboardIDs); | |
542 | $dashboardID = CRM_Utils_Array::value('dashboard_id', $dashboardIDs); | |
543 | $column = CRM_Utils_Array::value('column_no', $dashboardIDs, 0); | |
544 | $columns[$column][$dashboardID] = 0; | |
545 | } | |
546 | self::saveDashletChanges($columns, $contactID); | |
547 | return TRUE; | |
548 | } | |
549 | ||
6a488035 | 550 | /** |
fe482240 | 551 | * Reset dashlet cache. |
6a488035 | 552 | * |
6a0b768e TO |
553 | * @param int $contactID |
554 | * Reset cache only for specific contact. | |
6a488035 TO |
555 | * |
556 | * @return void | |
6a488035 | 557 | */ |
2aa397bc TO |
558 | public static function resetDashletCache($contactID = NULL) { |
559 | $whereClause = NULL; | |
6a488035 TO |
560 | $params = array(); |
561 | if ($contactID) { | |
562 | $whereClause = "WHERE contact_id = %1"; | |
563 | $params[1] = array($contactID, 'Integer'); | |
564 | } | |
565 | $query = "UPDATE civicrm_dashboard_contact SET content = NULL $whereClause"; | |
566 | $dao = CRM_Core_DAO::executeQuery($query, $params); | |
567 | } | |
568 | ||
569 | /** | |
fe482240 | 570 | * Delete Dashlet. |
6a488035 | 571 | * |
100fef9d | 572 | * @param int $dashletID |
2a6da8d7 | 573 | * |
6a488035 | 574 | * @return void |
6a488035 | 575 | */ |
00be9182 | 576 | public static function deleteDashlet($dashletID) { |
6a488035 TO |
577 | $dashlet = new CRM_Core_DAO_Dashboard(); |
578 | $dashlet->id = $dashletID; | |
579 | $dashlet->delete(); | |
15d9b3ae | 580 | return TRUE; |
6a488035 | 581 | } |
96025800 | 582 | |
6a488035 | 583 | } |