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
{
22 public function __construct() {
23 parent
::__construct();
27 * Takes an associative array and creates a groupOrganization object.
29 * @param array $params
30 * (reference ) an assoc array of name/value pairs.
32 * @return CRM_Contact_DAO_GroupOrganization
34 public static function add(&$params) {
35 if (!empty($params['group_organization'])) {
36 $params['id'] = $params['group_organization'];
38 $dataExists = self
::dataExists($params);
39 if (!$dataExists && empty($params['id'])) {
42 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
43 $groupOrganization->copyValues($params);
44 if (!isset($params['id'])) {
45 // we have ensured we have group_id & organization_id so we can do a find knowing that
46 // this can only find a matching record
47 $groupOrganization->find(TRUE);
49 $groupOrganization->save();
50 return $groupOrganization;
54 * Check if there is data to create the object.
56 * @param array $params
57 * (reference ) an assoc array of name/value pairs.
61 public static function dataExists($params) {
62 // return if no data present
63 if (!empty($params['organization_id']) && !empty($params['group_id'])) {
73 public static function retrieve($groupID, &$defaults) {
74 $dao = new CRM_Contact_DAO_GroupOrganization();
75 $dao->group_id
= $groupID;
76 if ($dao->find(TRUE)) {
77 $defaults['group_organization'] = $dao->id
;
78 $defaults['organization_id'] = $dao->organization_id
;
83 * Method to check group organization relationship exist.
85 * @param int $contactID
89 public static function hasGroupAssociated($contactID) {
90 $orgID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_GroupOrganization',
91 $contactID, 'group_id', 'organization_id'
100 * Delete Group Organization.
102 * @param int $groupOrganizationID
103 * Group organization id that needs to be deleted.
106 * no of deleted group organization on success, false otherwise
108 public static function deleteGroupOrganization($groupOrganizationID) {
110 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
111 $groupOrganization->id
= $groupOrganizationID;
113 $results = $groupOrganization->delete();