3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_BAO_GroupOrganization
extends CRM_Contact_DAO_GroupOrganization
{
20 * Takes an associative array and creates a groupOrganization object.
22 * @param array $params
23 * (reference ) an assoc array of name/value pairs.
25 * @return CRM_Contact_DAO_GroupOrganization
27 public static function add(&$params) {
28 if (!empty($params['group_organization'])) {
29 $params['id'] = $params['group_organization'];
31 $dataExists = self
::dataExists($params);
32 if (!$dataExists && empty($params['id'])) {
35 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
36 $groupOrganization->copyValues($params);
37 if (!isset($params['id'])) {
38 // we have ensured we have group_id & organization_id so we can do a find knowing that
39 // this can only find a matching record
40 $groupOrganization->find(TRUE);
42 $groupOrganization->save();
43 return $groupOrganization;
47 * Check if there is data to create the object.
49 * @param array $params
50 * (reference ) an assoc array of name/value pairs.
54 public static function dataExists($params) {
55 // return if no data present
56 if (!empty($params['organization_id']) && !empty($params['group_id'])) {
64 * @param array $defaults
66 public static function retrieve($groupID, &$defaults) {
67 $dao = new CRM_Contact_DAO_GroupOrganization();
68 $dao->group_id
= $groupID;
69 if ($dao->find(TRUE)) {
70 $defaults['group_organization'] = $dao->id
;
71 $defaults['organization_id'] = $dao->organization_id
;
76 * Method to check group organization relationship exist.
78 * @param int $contactID
82 public static function hasGroupAssociated($contactID) {
83 $orgID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_GroupOrganization',
84 $contactID, 'group_id', 'organization_id'
93 * Delete Group Organization.
95 * @param int $groupOrganizationID
96 * Group organization id that needs to be deleted.
99 * no of deleted group organization on success, false otherwise
101 public static function deleteGroupOrganization($groupOrganizationID) {
103 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
104 $groupOrganization->id
= $groupOrganizationID;
106 $results = $groupOrganization->delete();