Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
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 | |
ca5cec67 | 31 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
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 { | |
518fa0ee | 38 | |
3cfa8e5e | 39 | /** |
fe482240 | 40 | * Add Dashboard. |
3cfa8e5e | 41 | * |
6a0b768e TO |
42 | * @param array $params |
43 | * Values. | |
3cfa8e5e | 44 | * |
3cfa8e5e EM |
45 | * |
46 | * @return object | |
47 | */ | |
00be9182 | 48 | public static function create($params) { |
3cfa8e5e EM |
49 | $hook = empty($params['id']) ? 'create' : 'edit'; |
50 | CRM_Utils_Hook::pre($hook, 'Dashboard', CRM_Utils_Array::value('id', $params), $params); | |
51 | $dao = self::addDashlet($params); | |
52 | CRM_Utils_Hook::post($hook, 'Dashboard', $dao->id, $dao); | |
53 | return $dao; | |
54 | } | |
6a488035 TO |
55 | |
56 | /** | |
fe482240 | 57 | * Get the list of dashlets enabled by admin. |
6a488035 | 58 | * |
6a0b768e TO |
59 | * @param bool $all |
60 | * All or only active. | |
61 | * @param bool $checkPermission | |
62 | * All or only authorized for the current user. | |
6a488035 | 63 | * |
a6c01b45 CW |
64 | * @return array |
65 | * array of dashlets | |
6a488035 | 66 | */ |
00be9182 | 67 | public static function getDashlets($all = TRUE, $checkPermission = TRUE) { |
be2fb01f | 68 | $dashlets = []; |
6a488035 TO |
69 | $dao = new CRM_Core_DAO_Dashboard(); |
70 | ||
71 | if (!$all) { | |
72 | $dao->is_active = 1; | |
73 | } | |
74 | ||
75 | $dao->domain_id = CRM_Core_Config::domainID(); | |
76 | ||
77 | $dao->find(); | |
78 | while ($dao->fetch()) { | |
ee117e9c | 79 | if ($checkPermission && !self::checkPermission($dao->permission, $dao->permission_operator)) { |
6a488035 TO |
80 | continue; |
81 | } | |
82 | ||
be2fb01f | 83 | $values = []; |
6a488035 TO |
84 | CRM_Core_DAO::storeValues($dao, $values); |
85 | $dashlets[$dao->id] = $values; | |
86 | } | |
87 | ||
88 | return $dashlets; | |
89 | } | |
90 | ||
91 | /** | |
08727453 | 92 | * Get the list of dashlets for the current user or the specified user. |
6a488035 | 93 | * |
5aa910d4 JM |
94 | * Additionlly, initializes the dashboard with defaults if this is the |
95 | * user's first visit to their dashboard. | |
6a488035 | 96 | * |
6a0b768e | 97 | * @param int $contactID |
94864a5f | 98 | * Defaults to the current user. |
77b97be7 | 99 | * |
a6c01b45 CW |
100 | * @return array |
101 | * array of dashlets | |
6a488035 | 102 | */ |
94864a5f | 103 | public static function getContactDashlets($contactID = NULL) { |
3bdcd4ec | 104 | $contactID = $contactID ? $contactID : CRM_Core_Session::getLoggedInContactID(); |
be2fb01f | 105 | $dashlets = []; |
6a488035 | 106 | |
5aa910d4 | 107 | // Get contact dashboard dashlets. |
be2fb01f | 108 | $results = civicrm_api3('DashboardContact', 'get', [ |
94864a5f | 109 | 'contact_id' => $contactID, |
dd3770bc CW |
110 | 'is_active' => 1, |
111 | 'dashboard_id.is_active' => 1, | |
1a23f3fd | 112 | 'dashboard_id.domain_id' => CRM_Core_Config::domainID(), |
be2fb01f CW |
113 | 'options' => ['sort' => 'weight', 'limit' => 0], |
114 | 'return' => [ | |
dd3770bc CW |
115 | 'id', |
116 | 'weight', | |
117 | 'column_no', | |
dd3770bc CW |
118 | 'dashboard_id', |
119 | 'dashboard_id.name', | |
120 | 'dashboard_id.label', | |
121 | 'dashboard_id.url', | |
122 | 'dashboard_id.fullscreen_url', | |
a8f56d71 | 123 | 'dashboard_id.cache_minutes', |
dd3770bc CW |
124 | 'dashboard_id.permission', |
125 | 'dashboard_id.permission_operator', | |
be2fb01f CW |
126 | ], |
127 | ]); | |
5f3f6ec3 | 128 | |
94864a5f | 129 | foreach ($results['values'] as $item) { |
dd3770bc | 130 | if (self::checkPermission(CRM_Utils_Array::value('dashboard_id.permission', $item), CRM_Utils_Array::value('dashboard_id.permission_operator', $item))) { |
be2fb01f | 131 | $dashlets[$item['id']] = [ |
dd3770bc CW |
132 | 'dashboard_id' => $item['dashboard_id'], |
133 | 'weight' => $item['weight'], | |
134 | 'column_no' => $item['column_no'], | |
dd3770bc CW |
135 | 'name' => $item['dashboard_id.name'], |
136 | 'label' => $item['dashboard_id.label'], | |
137 | 'url' => $item['dashboard_id.url'], | |
a8f56d71 | 138 | 'cache_minutes' => $item['dashboard_id.cache_minutes'], |
7ec4b96d | 139 | 'fullscreen_url' => CRM_Utils_Array::value('dashboard_id.fullscreen_url', $item), |
be2fb01f | 140 | ]; |
6a488035 TO |
141 | } |
142 | } | |
143 | ||
dd3770bc | 144 | // If empty, then initialize default dashlets for this user. |
94864a5f | 145 | if (!$results['count']) { |
dd3770bc | 146 | // They may just have disabled all their dashlets. Check if any records exist for this contact. |
1a23f3fd | 147 | if (!civicrm_api3('DashboardContact', 'getcount', ['contact_id' => $contactID, 'dashboard_id.domain_id' => CRM_Core_Config::domainID()])) { |
dd3770bc CW |
148 | $dashlets = self::initializeDashlets(); |
149 | } | |
5aa910d4 | 150 | } |
94864a5f | 151 | |
5aa910d4 | 152 | return $dashlets; |
15d9b3ae N |
153 | } |
154 | ||
242055d3 CW |
155 | /** |
156 | * @return array | |
157 | */ | |
dd3770bc | 158 | public static function getContactDashletsForJS() { |
be2fb01f | 159 | $data = [[], []]; |
dd3770bc | 160 | foreach (self::getContactDashlets() as $item) { |
be2fb01f | 161 | $data[$item['column_no']][] = [ |
dd3770bc | 162 | 'id' => (int) $item['dashboard_id'], |
dd3770bc CW |
163 | 'name' => $item['name'], |
164 | 'title' => $item['label'], | |
165 | 'url' => self::parseUrl($item['url']), | |
a8f56d71 | 166 | 'cacheMinutes' => $item['cache_minutes'], |
dd3770bc | 167 | 'fullscreenUrl' => self::parseUrl($item['fullscreen_url']), |
be2fb01f | 168 | ]; |
dd3770bc CW |
169 | } |
170 | return $data; | |
171 | } | |
172 | ||
b5c2afd0 | 173 | /** |
fe482240 | 174 | * Setup default dashlets for new users. |
b5c2afd0 | 175 | * |
5aa910d4 JM |
176 | * When a user accesses their dashboard for the first time, set up |
177 | * the default dashlets. | |
178 | * | |
a6c01b45 | 179 | * @return array |
518fa0ee | 180 | * Array of dashboard_id's |
ad37ac8e | 181 | * @throws \CiviCRM_API3_Exception |
b5c2afd0 | 182 | */ |
94864a5f | 183 | public static function initializeDashlets() { |
be2fb01f CW |
184 | $dashlets = []; |
185 | $getDashlets = civicrm_api3("Dashboard", "get", [ | |
cf9ccf98 TO |
186 | 'domain_id' => CRM_Core_Config::domainID(), |
187 | 'option.limit' => 0, | |
188 | ]); | |
3bdcd4ec | 189 | $contactID = CRM_Core_Session::getLoggedInContactID(); |
be2fb01f CW |
190 | $allDashlets = CRM_Utils_Array::index(['name'], $getDashlets['values']); |
191 | $defaultDashlets = []; | |
192 | $defaults = ['blog' => 1, 'getting-started' => '0']; | |
c202dd9e | 193 | foreach ($defaults as $name => $column) { |
fbd19c80 | 194 | if (!empty($allDashlets[$name]) && !empty($allDashlets[$name]['id'])) { |
be2fb01f | 195 | $defaultDashlets[$name] = [ |
40c0dd53 | 196 | 'dashboard_id' => $allDashlets[$name]['id'], |
197 | 'is_active' => 1, | |
198 | 'column_no' => $column, | |
199 | 'contact_id' => $contactID, | |
be2fb01f | 200 | ]; |
40c0dd53 | 201 | } |
15d9b3ae N |
202 | } |
203 | CRM_Utils_Hook::dashboard_defaults($allDashlets, $defaultDashlets); | |
204 | if (is_array($defaultDashlets) && !empty($defaultDashlets)) { | |
5aa910d4 JM |
205 | foreach ($defaultDashlets as $id => $defaultDashlet) { |
206 | $dashboard_id = $defaultDashlet['dashboard_id']; | |
dd3770bc CW |
207 | $dashlet = $getDashlets['values'][$dashboard_id]; |
208 | if (!self::checkPermission(CRM_Utils_Array::value('permission', $dashlet), CRM_Utils_Array::value('permission_operator', $dashlet))) { | |
15d9b3ae N |
209 | continue; |
210 | } | |
211 | else { | |
212 | $assignDashlets = civicrm_api3("dashboard_contact", "create", $defaultDashlet); | |
94864a5f | 213 | $values = $assignDashlets['values'][$assignDashlets['id']]; |
be2fb01f | 214 | $dashlets[$assignDashlets['id']] = [ |
dd3770bc CW |
215 | 'dashboard_id' => $values['dashboard_id'], |
216 | 'weight' => $values['weight'], | |
217 | 'column_no' => $values['column_no'], | |
dd3770bc CW |
218 | 'name' => $dashlet['name'], |
219 | 'label' => $dashlet['label'], | |
a8f56d71 | 220 | 'cache_minutes' => $dashlet['cache_minutes'], |
dd3770bc | 221 | 'url' => $dashlet['url'], |
7ec4b96d | 222 | 'fullscreen_url' => CRM_Utils_Array::value('fullscreen_url', $dashlet), |
be2fb01f | 223 | ]; |
6a488035 | 224 | } |
6a488035 TO |
225 | } |
226 | } | |
5aa910d4 | 227 | return $dashlets; |
6a488035 | 228 | } |
08727453 | 229 | |
dd3770bc CW |
230 | /** |
231 | * @param $url | |
232 | * @return string | |
233 | */ | |
234 | public static function parseUrl($url) { | |
8f6fefed | 235 | // Check if it is already a fully-formed url |
7ec4b96d | 236 | if ($url && substr($url, 0, 4) != 'http' && $url[0] != '/') { |
dd3770bc | 237 | $urlParam = explode('?', $url); |
8f6fefed | 238 | $url = CRM_Utils_System::url($urlParam[0], CRM_Utils_Array::value(1, $urlParam), FALSE, NULL, FALSE); |
dd3770bc CW |
239 | } |
240 | return $url; | |
241 | } | |
6a488035 TO |
242 | |
243 | /** | |
fe482240 | 244 | * Check dashlet permission for current user. |
6a488035 | 245 | * |
6a0b768e TO |
246 | * @param string $permission |
247 | * Comma separated list. | |
c490a46a | 248 | * @param string $operator |
6a488035 | 249 | * |
408b79bf | 250 | * @return bool |
a6c01b45 | 251 | * true if use has permission else false |
6a488035 | 252 | */ |
00be9182 | 253 | public static function checkPermission($permission, $operator) { |
6a488035 TO |
254 | if ($permission) { |
255 | $permissions = explode(',', $permission); | |
256 | $config = CRM_Core_Config::singleton(); | |
257 | ||
258 | static $allComponents; | |
259 | if (!$allComponents) { | |
260 | $allComponents = CRM_Core_Component::getNames(); | |
261 | } | |
262 | ||
263 | $hasPermission = FALSE; | |
264 | foreach ($permissions as $key) { | |
265 | $showDashlet = TRUE; | |
266 | ||
267 | $componentName = NULL; | |
268 | if (strpos($key, 'access') === 0) { | |
269 | $componentName = trim(substr($key, 6)); | |
270 | if (!in_array($componentName, $allComponents)) { | |
271 | $componentName = NULL; | |
272 | } | |
273 | } | |
274 | ||
275 | // hack to handle case permissions | |
cf9ccf98 TO |
276 | if (!$componentName |
277 | && in_array($key, ['access my cases and activities', 'access all cases and activities']) | |
353ffa53 | 278 | ) { |
6a488035 TO |
279 | $componentName = 'CiviCase'; |
280 | } | |
281 | ||
282 | //hack to determine if it's a component related permission | |
283 | if ($componentName) { | |
284 | if (!in_array($componentName, $config->enableComponents) || | |
285 | !CRM_Core_Permission::check($key) | |
286 | ) { | |
287 | $showDashlet = FALSE; | |
288 | if ($operator == 'AND') { | |
289 | return $showDashlet; | |
290 | } | |
291 | } | |
292 | else { | |
293 | $hasPermission = TRUE; | |
294 | } | |
295 | } | |
296 | elseif (!CRM_Core_Permission::check($key)) { | |
297 | $showDashlet = FALSE; | |
298 | if ($operator == 'AND') { | |
299 | return $showDashlet; | |
300 | } | |
301 | } | |
302 | else { | |
303 | $hasPermission = TRUE; | |
304 | } | |
305 | } | |
306 | ||
307 | if (!$showDashlet && !$hasPermission) { | |
308 | return FALSE; | |
309 | } | |
310 | else { | |
311 | return TRUE; | |
312 | } | |
313 | } | |
314 | else { | |
315 | // if permission is not set consider everyone has permission to access it. | |
316 | return TRUE; | |
317 | } | |
318 | } | |
319 | ||
320 | /** | |
242055d3 | 321 | * Save changes made by user to the Dashlet. |
6a488035 | 322 | * |
6a0b768e | 323 | * @param array $columns |
6a488035 | 324 | * |
100fef9d | 325 | * @param int $contactID |
77b97be7 EM |
326 | * |
327 | * @throws RuntimeException | |
6a488035 | 328 | */ |
2aa397bc | 329 | public static function saveDashletChanges($columns, $contactID = NULL) { |
15d9b3ae | 330 | if (!$contactID) { |
ce2cc43e | 331 | $contactID = CRM_Core_Session::getLoggedInContactID(); |
15d9b3ae N |
332 | } |
333 | ||
f583d89b TO |
334 | if (empty($contactID)) { |
335 | throw new RuntimeException("Failed to determine contact ID"); | |
336 | } | |
6a488035 | 337 | |
be2fb01f | 338 | $dashletIDs = []; |
6a488035 TO |
339 | if (is_array($columns)) { |
340 | foreach ($columns as $colNo => $dashlets) { | |
408b79bf | 341 | if (!is_int($colNo)) { |
6a488035 TO |
342 | continue; |
343 | } | |
344 | $weight = 1; | |
345 | foreach ($dashlets as $dashletID => $isMinimized) { | |
00c27b41 CW |
346 | $dashletID = (int) $dashletID; |
347 | $query = "INSERT INTO civicrm_dashboard_contact | |
242055d3 CW |
348 | (weight, column_no, is_active, dashboard_id, contact_id) |
349 | VALUES({$weight}, {$colNo}, 1, {$dashletID}, {$contactID}) | |
350 | ON DUPLICATE KEY UPDATE weight = {$weight}, column_no = {$colNo}, is_active = 1"; | |
6a488035 | 351 | // fire update query for each column |
00c27b41 | 352 | CRM_Core_DAO::executeQuery($query); |
6a488035 TO |
353 | |
354 | $dashletIDs[] = $dashletID; | |
355 | $weight++; | |
356 | } | |
357 | } | |
358 | } | |
359 | ||
d3eb2e98 CW |
360 | // Find dashlets in this domain. |
361 | $domainDashlets = civicrm_api3('Dashboard', 'get', [ | |
362 | 'return' => array('id'), | |
363 | 'domain_id' => CRM_Core_Config::domainID(), | |
cbf61ce3 | 364 | 'options' => ['limit' => 0], |
d3eb2e98 CW |
365 | ]); |
366 | ||
367 | // Get the array of IDs. | |
368 | $domainDashletIDs = []; | |
369 | if ($domainDashlets['is_error'] == 0) { | |
4020bce8 | 370 | $domainDashletIDs = CRM_Utils_Array::collect('id', $domainDashlets['values']); |
d3eb2e98 CW |
371 | } |
372 | ||
373 | // Restrict query to Dashlets in this domain. | |
374 | $domainDashletClause = !empty($domainDashletIDs) ? "dashboard_id IN (" . implode(',', $domainDashletIDs) . ")" : '(1)'; | |
375 | ||
c0543d08 CW |
376 | // Target only those Dashlets which are inactive. |
377 | $dashletClause = $dashletIDs ? "dashboard_id NOT IN (" . implode(',', $dashletIDs) . ")" : '(1)'; | |
378 | ||
379 | // Build params. | |
380 | $params = [ | |
381 | 1 => [$contactID, 'Integer'], | |
382 | ]; | |
383 | ||
384 | // Build query. | |
00c27b41 CW |
385 | $updateQuery = "UPDATE civicrm_dashboard_contact |
386 | SET is_active = 0 | |
d3eb2e98 CW |
387 | WHERE $domainDashletClause |
388 | AND $dashletClause | |
c0543d08 | 389 | AND contact_id = %1"; |
6a488035 | 390 | |
c0543d08 CW |
391 | // Disable inactive widgets. |
392 | CRM_Core_DAO::executeQuery($updateQuery, $params); | |
6a488035 TO |
393 | } |
394 | ||
395 | /** | |
fe482240 | 396 | * Add dashlets. |
6a488035 | 397 | * |
6a0b768e | 398 | * @param array $params |
6a488035 | 399 | * |
a6c01b45 CW |
400 | * @return object |
401 | * $dashlet returns dashlet object | |
6a488035 | 402 | */ |
00be9182 | 403 | public static function addDashlet(&$params) { |
6a488035 | 404 | |
32c93376 | 405 | // special case to handle duplicate entries for report instances |
15d9b3ae N |
406 | $dashboardID = CRM_Utils_Array::value('id', $params); |
407 | ||
a7488080 | 408 | if (!empty($params['instanceURL'])) { |
6a488035 TO |
409 | $query = "SELECT id |
410 | FROM `civicrm_dashboard` | |
411 | WHERE url LIKE '" . CRM_Utils_Array::value('instanceURL', $params) . "&%'"; | |
412 | $dashboardID = CRM_Core_DAO::singleValueQuery($query); | |
413 | } | |
414 | ||
415 | $dashlet = new CRM_Core_DAO_Dashboard(); | |
416 | ||
417 | if (!$dashboardID) { | |
1a23f3fd CW |
418 | |
419 | // Assign domain before search to allow identical dashlets in different domains. | |
420 | if (empty($params['domain_id'])) { | |
421 | $dashlet->domain_id = CRM_Core_Config::domainID(); | |
422 | } | |
420019a6 CW |
423 | else { |
424 | $dashlet->domain_id = CRM_Utils_Array::value('domain_id', $params); | |
425 | } | |
1a23f3fd CW |
426 | |
427 | // Try and find an existing dashlet - it will be updated if found. | |
a7488080 | 428 | if (!empty($params['name'])) { |
15d9b3ae N |
429 | $dashlet->name = CRM_Utils_Array::value('name', $params); |
430 | $dashlet->find(TRUE); | |
431 | } | |
432 | else { | |
433 | $dashlet->url = CRM_Utils_Array::value('url', $params); | |
434 | $dashlet->find(TRUE); | |
435 | } | |
1a23f3fd | 436 | |
6a488035 TO |
437 | } |
438 | else { | |
439 | $dashlet->id = $dashboardID; | |
440 | } | |
441 | ||
442 | if (is_array(CRM_Utils_Array::value('permission', $params))) { | |
443 | $params['permission'] = implode(',', $params['permission']); | |
444 | } | |
445 | $dashlet->copyValues($params); | |
6a488035 TO |
446 | $dashlet->save(); |
447 | ||
448 | // now we need to make dashlet entries for each contact | |
449 | self::addContactDashlet($dashlet); | |
450 | ||
451 | return $dashlet; | |
452 | } | |
453 | ||
454 | /** | |
fe482240 | 455 | * Update contact dashboard with new dashlet. |
6a488035 | 456 | * |
192d36c5 | 457 | * @param object $dashlet |
6a488035 | 458 | */ |
00be9182 | 459 | public static function addContactDashlet($dashlet) { |
6a488035 TO |
460 | $admin = CRM_Core_Permission::check('administer CiviCRM'); |
461 | ||
462 | // if dashlet is created by admin then you need to add it all contacts. | |
463 | // else just add to contact who is creating this dashlet | |
be2fb01f | 464 | $contactIDs = []; |
6a488035 TO |
465 | if ($admin) { |
466 | $query = "SELECT distinct( contact_id ) | |
a3138c9e | 467 | FROM civicrm_dashboard_contact"; |
6a488035 TO |
468 | $dao = CRM_Core_DAO::executeQuery($query); |
469 | while ($dao->fetch()) { | |
a3138c9e | 470 | $contactIDs[$dao->contact_id] = NULL; |
6a488035 TO |
471 | } |
472 | } | |
473 | else { | |
474 | //Get the id of Logged in User | |
df099613 | 475 | $contactID = CRM_Core_Session::getLoggedInContactID(); |
22e263ad | 476 | if (!empty($contactID)) { |
a3138c9e | 477 | $contactIDs[$contactID] = NULL; |
155a0ed0 | 478 | } |
6a488035 TO |
479 | } |
480 | ||
a3138c9e JM |
481 | // Remove contact ids that already have this dashlet to avoid DB |
482 | // constraint violation. | |
483 | $query = "SELECT distinct( contact_id ) | |
484 | FROM civicrm_dashboard_contact WHERE dashboard_id = {$dashlet->id}"; | |
485 | $dao = CRM_Core_DAO::executeQuery($query); | |
a3138c9e | 486 | while ($dao->fetch()) { |
cc4988ae | 487 | if (array_key_exists($dao->contact_id, $contactIDs)) { |
a3138c9e JM |
488 | unset($contactIDs[$dao->contact_id]); |
489 | } | |
490 | } | |
6a488035 | 491 | if (!empty($contactIDs)) { |
a3138c9e | 492 | foreach ($contactIDs as $contactID => $value) { |
6a488035 TO |
493 | $valuesArray[] = " ( {$dashlet->id}, {$contactID} )"; |
494 | } | |
6a488035 TO |
495 | $valuesString = implode(',', $valuesArray); |
496 | $query = " | |
497 | INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id ) | |
498 | VALUES {$valuesString}"; | |
499 | ||
500 | CRM_Core_DAO::executeQuery($query); | |
501 | } | |
502 | } | |
503 | ||
dcf56200 | 504 | /** |
6a0b768e TO |
505 | * @param array $params |
506 | * Each item is a spec for a dashlet on the contact's dashboard. | |
dcf56200 TO |
507 | * @return bool |
508 | */ | |
00be9182 | 509 | public static function addContactDashletToDashboard(&$params) { |
15d9b3ae | 510 | $valuesString = NULL; |
be2fb01f | 511 | $columns = []; |
15d9b3ae N |
512 | foreach ($params as $dashboardIDs) { |
513 | $contactID = CRM_Utils_Array::value('contact_id', $dashboardIDs); | |
514 | $dashboardID = CRM_Utils_Array::value('dashboard_id', $dashboardIDs); | |
515 | $column = CRM_Utils_Array::value('column_no', $dashboardIDs, 0); | |
516 | $columns[$column][$dashboardID] = 0; | |
517 | } | |
518 | self::saveDashletChanges($columns, $contactID); | |
519 | return TRUE; | |
520 | } | |
521 | ||
6a488035 | 522 | /** |
fe482240 | 523 | * Delete Dashlet. |
6a488035 | 524 | * |
100fef9d | 525 | * @param int $dashletID |
2a6da8d7 | 526 | * |
192d36c5 | 527 | * @return bool |
6a488035 | 528 | */ |
00be9182 | 529 | public static function deleteDashlet($dashletID) { |
6a488035 TO |
530 | $dashlet = new CRM_Core_DAO_Dashboard(); |
531 | $dashlet->id = $dashletID; | |
a60c0bc8 SL |
532 | if (!$dashlet->find(TRUE)) { |
533 | return FALSE; | |
534 | } | |
6a488035 | 535 | $dashlet->delete(); |
15d9b3ae | 536 | return TRUE; |
6a488035 | 537 | } |
96025800 | 538 | |
6a488035 | 539 | } |