/** * Get the list of dashlets for the current user or the specified user. * * Additionlly, initializes the dashboard with defaults if this is the * user's first visit to their dashboard. * * @param bool $flatFormat * This is true if you want simple associated. * array of all the contact's dashlets whether or not they are enabled. * * @param int $contactID * Provide the dashlets for the contact id. * passed rather than the current user. * * @return array * array of dashlets */ public static function getContactDashlets($flatFormat = FALSE, $contactID = NULL) { $dashlets = array(); // Get contact dashboard dashlets. $hasDashlets = FALSE; $dao = new CRM_Contact_DAO_DashboardContact(); $dao->contact_id = $contactID ? $contactID : CRM_Core_Session::singleton()->getLoggedInContactID(); $dao->orderBy('column_no asc, weight asc'); $dao->find(); // The available list will only include those which are valid for the domain. $availableDashlets = self::getDashlets(); 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. if (!empty($availableDashlets[$dao->dashboard_id]) && $availableDashlets[$dao->dashboard_id]['is_active']) { $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; } } } if ($flatFormat) { return $dashlets; } // If empty, then initialize contact dashboard for this user. if (!$hasDashlets) { return self::initializeDashlets($flatFormat); } return $dashlets; }
/** * Function to get the list of dashlets for a contact * and if there are no dashlets for contact return default dashlets and update * contact's preference entry * * @param int $contactID contactID * * @return array $dashlets array of dashlets * @access public * @static */ static function getContactDashlets($flatFormat = false) { $dashlets = array(); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // get contact dashboard dashlets $hasDashlets = false; require_once 'CRM/Contact/DAO/DashboardContact.php'; $dao = new CRM_Contact_DAO_DashboardContact(); $dao->contact_id = $contactID; $dao->orderBy('column_no asc, weight asc'); $dao->find(); while ($dao->fetch()) { if (!$flatFormat) { $hasDashlets = true; if (!$dao->is_active) { continue; } // 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; } } if ($flatFormat) { return $dashlets; } // if empty then make entry in contact dashboard for this contact if (empty($dashlets) && !$hasDashlets) { $defaultDashlets = self::getDashlets(); //now you need make dashlet entries for logged in contact // need to optimize this sql foreach ($defaultDashlets as $key => $values) { $valuesArray[] = " ( {$key}, {$contactID} )"; } if (!empty($defaultDashlets)) { $valuesString = implode(',', $valuesArray); $query = "\n INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )\n VALUES {$valuesString}"; CRM_Core_DAO::executeQuery($query); } } return $dashlets; }
/** * Function to get the list of dashlets for a contact * * Initializes the dashboard with defaults if this is the user's first visit to their dashboard * * @param boolean $flatFormat this is true if you want simple associated array of contact dashlets * * @param null $contactID * * @return array $dashlets array of dashlets * @access public * @static */ static function getContactDashlets($flatFormat = FALSE, $contactID = NULL) { $dashlets = array(); if (!$contactID) { $contactID = CRM_Core_Session::singleton()->get('userID'); } // get contact dashboard dashlets $hasDashlets = FALSE; $dao = new CRM_Contact_DAO_DashboardContact(); $dao->contact_id = $contactID; $dao->orderBy('column_no asc, weight asc'); $dao->find(); while ($dao->fetch()) { $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; } } if ($flatFormat) { return $dashlets; } // If empty then initialize contact dashboard for this user $defaultDashlet = self::initializeDashlets($hasDashlets); return $defaultDashlet ? $defaultDashlet : $dashlets; }