- $hasDashlets = FALSE;
- $dao = new CRM_Contact_DAO_DashboardContact();
- $dao->contact_id = $contactID;
- $dao->orderBy('column_no asc, weight asc');
- $dao->find();
- while ($dao->fetch()) {
- // When a dashlet is removed, it stays in the table with status disabled,
- // so even if a user decides not to have any dashlets show, they will still
- // have records in the table to indicate that we are not newly initializing.
- $hasDashlets = TRUE;
- if (!$flatFormat) {
- if ($dao->is_active) {
- // append weight so that order is preserved.
- $dashlets[$dao->column_no]["{$dao->weight}-{$dao->dashboard_id}"] = $dao->is_minimized;
- }
- }
- else {
- $dashlets[$dao->dashboard_id] = $dao->dashboard_id;
+ $results = civicrm_api3('DashboardContact', 'get', array(
+ 'contact_id' => $contactID,
+ 'is_active' => 1,
+ 'dashboard_id.is_active' => 1,
+ 'options' => array('sort' => 'weight'),
+ 'return' => array(
+ 'id',
+ 'weight',
+ 'column_no',
+ 'is_minimized',
+ 'dashboard_id',
+ 'dashboard_id.name',
+ 'dashboard_id.label',
+ 'dashboard_id.url',
+ 'dashboard_id.fullscreen_url',
+ 'dashboard_id.permission',
+ 'dashboard_id.permission_operator',
+ ),
+ ));
+
+ foreach ($results['values'] as $item) {
+ if (self::checkPermission(CRM_Utils_Array::value('dashboard_id.permission', $item), CRM_Utils_Array::value('dashboard_id.permission_operator', $item))) {
+ $dashlets[$item['id']] = array(
+ 'dashboard_id' => $item['dashboard_id'],
+ 'weight' => $item['weight'],
+ 'column_no' => $item['column_no'],
+ 'is_minimized' => $item['is_minimized'],
+ 'name' => $item['dashboard_id.name'],
+ 'label' => $item['dashboard_id.label'],
+ 'url' => $item['dashboard_id.url'],
+ 'fullscreen_url' => $item['dashboard_id.fullscreen_url'],
+ );