Merge pull request #22928 from artfulrobot/artfulrobot-title-double-html-encoding
[civicrm-core.git] / CRM / Contact / BAO / GroupOrganization.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Contact_BAO_GroupOrganization extends CRM_Contact_DAO_GroupOrganization {
18
19 /**
20 * Takes an associative array and creates a groupOrganization object.
21 *
22 * @param array $params
23 * (reference ) an assoc array of name/value pairs.
24 *
25 * @return CRM_Contact_DAO_GroupOrganization
26 */
27 public static function add(&$params) {
28 if (!empty($params['group_organization'])) {
29 $params['id'] = $params['group_organization'];
30 }
31 $dataExists = self::dataExists($params);
32 if (!$dataExists && empty($params['id'])) {
33 return NULL;
34 }
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);
41 }
42 $groupOrganization->save();
43 return $groupOrganization;
44 }
45
46 /**
47 * Check if there is data to create the object.
48 *
49 * @param array $params
50 * (reference ) an assoc array of name/value pairs.
51 *
52 * @return bool
53 */
54 public static function dataExists($params) {
55 // return if no data present
56 if (!empty($params['organization_id']) && !empty($params['group_id'])) {
57 return TRUE;
58 }
59 return FALSE;
60 }
61
62 /**
63 * @param int $groupID
64 * @param array $defaults
65 */
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;
72 }
73 }
74
75 /**
76 * Method to check group organization relationship exist.
77 *
78 * @param int $contactID
79 *
80 * @return bool
81 */
82 public static function hasGroupAssociated($contactID) {
83 $orgID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupOrganization',
84 $contactID, 'group_id', 'organization_id'
85 );
86 if ($orgID) {
87 return TRUE;
88 }
89 return FALSE;
90 }
91
92 /**
93 * Delete Group Organization.
94 *
95 * @param int $groupOrganizationID
96 * Group organization id that needs to be deleted.
97 *
98 * @return int|null
99 * no of deleted group organization on success, false otherwise
100 */
101 public static function deleteGroupOrganization($groupOrganizationID) {
102 $results = NULL;
103 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
104 $groupOrganization->id = $groupOrganizationID;
105
106 $results = $groupOrganization->delete();
107
108 return $results;
109 }
110
111 }