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