return FALSE;
}
}
+
+
+ /**
+ * Delete a contact-related object that has an 'is_primary' field
+ * Ensures that is_primary gets assigned to another object if available
+ * Also calls pre/post hooks
+ *
+ * @var $type: object type
+ * @var $id: object id
+ */
+ public static function deleteObjectWithPrimary($type, $id) {
+ if (!$id || !is_numeric($id)) {
+ return false;
+ }
+ $daoName = "CRM_Core_DAO_$type";
+ $obj = new $daoName();
+ $obj->id = $id;
+ $obj->find();
+ if ($obj->fetch()) {
+ CRM_Utils_Hook::pre('delete', $type, $id, CRM_Core_DAO::$_nullArray);
+ $contactId = $obj->contact_id;
+ $obj->delete();
+ }
+ else {
+ return false;
+ }
+ $dao = new $daoName();
+ $dao->contact_id = $contactId;
+ $dao->is_primary = 1;
+ // Pick another record to be primary (if one isn't already)
+ if (!$dao->find(TRUE)) {
+ $dao->is_primary = 0;
+ $dao->find();
+ if ($dao->fetch()) {
+ $dao->is_primary = 1;
+ $dao->save();
+ }
+ }
+ $dao->free();
+ CRM_Utils_Hook::post('delete', $type, $id, $obj);
+ $obj->free();
+ }
}
);
}
}
+
+ /**
+ * Call common delete function
+ */
+ static function del($id) {
+ CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Address', $id);
+ }
}
static function isMultipleBulkMail() {
return CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'civimail_multiple_bulk_emails', NULL, FALSE);
}
+
+ /**
+ * Call common delete function
+ */
+ static function del($id) {
+ CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Email', $id);
+ }
}
}
return $ims;
}
+
+ /**
+ * Call common delete function
+ */
+ static function del($id) {
+ CRM_Contact_BAO_Contact::deleteObjectWithPrimary('IM', $id);
+ }
}
*/
static function add(&$params) {
$hook = empty($params['id']) ? 'create' : 'edit';
- CRM_Utils_Hook::pre($hook, 'openId', CRM_Utils_Array::value('id', $params), $params);
+ CRM_Utils_Hook::pre($hook, 'OpenID', CRM_Utils_Array::value('id', $params), $params);
$openId = new CRM_Core_DAO_OpenID();
$openId->copyValues($params);
$openId->save();
- CRM_Utils_Hook::post($hook, 'openId', $openId->id, $openId);
+ CRM_Utils_Hook::post($hook, 'OpenID', $openId->id, $openId);
return $openId;
}
}
return $openids;
}
+
+ /**
+ * Call common delete function
+ */
+ static function del($id) {
+ CRM_Contact_BAO_Contact::deleteObjectWithPrimary('OpenID', $id);
+ }
}
CRM_Core_DAO::executeQuery($query, $params);
}
}
+
+ /**
+ * Call common delete function
+ */
+ static function del($id) {
+ CRM_Contact_BAO_Contact::deleteObjectWithPrimary('Phone', $id);
+ }
}