* array of dashlets
*/
public static function getContactDashlets($contactID = NULL) {
- $contactID = $contactID ? $contactID : CRM_Core_Session::singleton()->getLoggedInContactID();
+ $contactID = $contactID ? $contactID : CRM_Core_Session::getLoggedInContactID();
$dashlets = array();
// Get contact dashboard dashlets.
'contact_id' => $contactID,
'is_active' => 1,
'dashboard_id.is_active' => 1,
- 'options' => array('sort' => 'weight'),
+ 'options' => array('sort' => 'weight', 'limit' => 0),
'return' => array(
'id',
'weight',
'domain_id' => CRM_Core_Config::domainID(),
'option.limit' => 0,
));
- $contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
+ $contactID = CRM_Core_Session::getLoggedInContactID();
$allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']);
$defaultDashlets = array();
$defaults = array('blog' => 1, 'getting-started' => '0');
$contactIDs = array();
if ($admin) {
$query = "SELECT distinct( contact_id )
- FROM civicrm_dashboard_contact
- WHERE contact_id NOT IN (
- SELECT distinct( contact_id )
- FROM civicrm_dashboard_contact WHERE dashboard_id = {$dashlet->id}
- )";
-
+ FROM civicrm_dashboard_contact";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
- $contactIDs[] = $dao->contact_id;
+ $contactIDs[$dao->contact_id] = NULL;
}
}
else {
//Get the id of Logged in User
- $session = CRM_Core_Session::singleton();
- $contactID = $session->get('userID');
+ $contactID = CRM_Core_Session::getLoggedInContactID();
if (!empty($contactID)) {
- $contactIDs[] = $session->get('userID');
+ $contactIDs[$contactID] = NULL;
}
}
+ // Remove contact ids that already have this dashlet to avoid DB
+ // constraint violation.
+ $query = "SELECT distinct( contact_id )
+ FROM civicrm_dashboard_contact WHERE dashboard_id = {$dashlet->id}";
+ $dao = CRM_Core_DAO::executeQuery($query);
+ while ($dao->fetch()) {
+ if (array_key_exists($dao->contact_id, $contactIDs)) {
+ unset($contactIDs[$dao->contact_id]);
+ }
+ }
if (!empty($contactIDs)) {
- foreach ($contactIDs as $contactID) {
+ foreach ($contactIDs as $contactID => $value) {
$valuesArray[] = " ( {$dashlet->id}, {$contactID} )";
}
-
$valuesString = implode(',', $valuesArray);
$query = "
INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )
public static function deleteDashlet($dashletID) {
$dashlet = new CRM_Core_DAO_Dashboard();
$dashlet->id = $dashletID;
+ if (!$dashlet->find(TRUE)) {
+ return FALSE;
+ }
$dashlet->delete();
return TRUE;
}