Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_BAO_GroupOrganization extends CRM_Contact_DAO_GroupOrganization { | |
34 | ||
35 | /** | |
fe482240 | 36 | * Class constructor. |
6a488035 | 37 | */ |
00be9182 | 38 | public function __construct() { |
6a488035 TO |
39 | parent::__construct(); |
40 | } | |
41 | ||
42 | /** | |
fe482240 | 43 | * Takes an associative array and creates a groupOrganization object. |
6a488035 | 44 | * |
77c5b619 TO |
45 | * @param array $params |
46 | * (reference ) an assoc array of name/value pairs. | |
6a488035 | 47 | * |
f8d78294 | 48 | * @return CRM_Contact_DAO_GroupOrganization |
6a488035 | 49 | */ |
00be9182 | 50 | public static function add(&$params) { |
1237d8d7 | 51 | if (!empty($params['group_organization'])) { |
52 | $params['id'] = $params['group_organization']; | |
53 | } | |
54 | $dataExists = self::dataExists($params); | |
55 | if (!$dataExists && empty($params['id'])) { | |
6a488035 TO |
56 | return NULL; |
57 | } | |
58 | $groupOrganization = new CRM_Contact_DAO_GroupOrganization(); | |
1237d8d7 | 59 | $groupOrganization->copyValues($params); |
60 | if (!isset($params['id'])) { | |
61 | // we have ensured we have group_id & organization_id so we can do a find knowing that | |
62 | // this can only find a matching record | |
63 | $groupOrganization->find(TRUE); | |
64 | } | |
6a488035 TO |
65 | $groupOrganization->save(); |
66 | return $groupOrganization; | |
67 | } | |
68 | ||
6a488035 | 69 | /** |
fe482240 | 70 | * Check if there is data to create the object. |
6a488035 | 71 | * |
77c5b619 TO |
72 | * @param array $params |
73 | * (reference ) an assoc array of name/value pairs. | |
6a488035 | 74 | * |
bed98343 | 75 | * @return bool |
6a488035 | 76 | */ |
00be9182 | 77 | public static function dataExists($params) { |
6a488035 | 78 | // return if no data present |
8cc574cf | 79 | if (!empty($params['organization_id']) && !empty($params['group_id'])) { |
6a488035 TO |
80 | return TRUE; |
81 | } | |
82 | return FALSE; | |
83 | } | |
84 | ||
86538308 | 85 | /** |
100fef9d | 86 | * @param int $groupID |
86538308 EM |
87 | * @param $defaults |
88 | */ | |
00be9182 | 89 | public static function retrieve($groupID, &$defaults) { |
6a488035 TO |
90 | $dao = new CRM_Contact_DAO_GroupOrganization(); |
91 | $dao->group_id = $groupID; | |
92 | if ($dao->find(TRUE)) { | |
93 | $defaults['group_organization'] = $dao->id; | |
94 | $defaults['organization_id'] = $dao->organization_id; | |
95 | } | |
96 | } | |
97 | ||
98 | /** | |
fe482240 | 99 | * Method to check group organization relationship exist. |
6a488035 | 100 | * |
c490a46a | 101 | * @param int $contactID |
6a488035 | 102 | * |
bed98343 | 103 | * @return bool |
6a488035 | 104 | */ |
00be9182 | 105 | public static function hasGroupAssociated($contactID) { |
6a488035 TO |
106 | $orgID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupOrganization', |
107 | $contactID, 'group_id', 'organization_id' | |
108 | ); | |
109 | if ($orgID) { | |
110 | return TRUE; | |
111 | } | |
112 | return FALSE; | |
113 | } | |
114 | ||
115 | /** | |
fe482240 | 116 | * Delete Group Organization. |
6a488035 | 117 | * |
77c5b619 TO |
118 | * @param int $groupOrganizationID |
119 | * Group organization id that needs to be deleted. | |
6a488035 | 120 | * |
72b3a70c CW |
121 | * @return int|null |
122 | * no of deleted group organization on success, false otherwise | |
6a488035 | 123 | */ |
00be9182 | 124 | public static function deleteGroupOrganization($groupOrganizationID) { |
6a488035 TO |
125 | $results = NULL; |
126 | $groupOrganization = new CRM_Contact_DAO_GroupOrganization(); | |
127 | $groupOrganization->id = $groupOrganizationID; | |
128 | ||
129 | $results = $groupOrganization->delete(); | |
130 | ||
131 | return $results; | |
132 | } | |
96025800 | 133 | |
6a488035 | 134 | } |