Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Contact_BAO_GroupOrganization extends CRM_Contact_DAO_GroupOrganization { | |
36 | ||
37 | /** | |
38 | * class constructor | |
39 | */ | |
40 | function __construct() { | |
41 | parent::__construct(); | |
42 | } | |
43 | ||
44 | /** | |
45 | * takes an associative array and creates a groupOrganization object | |
46 | * | |
47 | * @param array $params (reference ) an assoc array of name/value pairs | |
48 | * | |
49 | * @return void | |
50 | * @access public | |
51 | * @static | |
52 | */ | |
53 | static function add(&$params) { | |
54 | $formatedValues = array(); | |
55 | self::formatValues($params, $formatedValues); | |
56 | $dataExists = self::dataExists($formatedValues); | |
57 | if (!$dataExists) { | |
58 | return NULL; | |
59 | } | |
60 | $groupOrganization = new CRM_Contact_DAO_GroupOrganization(); | |
61 | $groupOrganization->copyValues($formatedValues); | |
62 | $groupOrganization->save(); | |
63 | return $groupOrganization; | |
64 | } | |
65 | ||
66 | /** | |
67 | * Format the params | |
68 | * | |
69 | * @param array $params (reference ) an assoc array of name/value pairs | |
70 | * @param array $formatedValues (reference ) an assoc array of name/value pairs | |
71 | * | |
72 | * @return void | |
73 | * @access public | |
74 | * @static | |
75 | */ | |
76 | static function formatValues(&$params, &$formatedValues) { | |
77 | if (CRM_Utils_Array::value('group_organization', $params)) { | |
78 | $formatedValues['id'] = $params['group_organization']; | |
79 | } | |
80 | ||
81 | if (CRM_Utils_Array::value('group_id', $params)) { | |
82 | $formatedValues['group_id'] = $params['group_id']; | |
83 | } | |
84 | ||
85 | if (CRM_Utils_Array::value('organization_id', $params)) { | |
86 | $formatedValues['organization_id'] = $params['organization_id']; | |
87 | } | |
88 | } | |
89 | ||
90 | /** | |
91 | * Check if there is data to create the object | |
92 | * | |
93 | * @param array $params (reference ) an assoc array of name/value pairs | |
94 | * | |
95 | * @return boolean | |
96 | * @access public | |
97 | * @static | |
98 | */ | |
99 | static function dataExists($params) { | |
100 | // return if no data present | |
101 | if (CRM_Utils_Array::value('organization_id', $params) && | |
102 | CRM_Utils_Array::value('group_id', $params) | |
103 | ) { | |
104 | return TRUE; | |
105 | } | |
106 | return FALSE; | |
107 | } | |
108 | ||
109 | static function retrieve($groupID, &$defaults) { | |
110 | $dao = new CRM_Contact_DAO_GroupOrganization(); | |
111 | $dao->group_id = $groupID; | |
112 | if ($dao->find(TRUE)) { | |
113 | $defaults['group_organization'] = $dao->id; | |
114 | $defaults['organization_id'] = $dao->organization_id; | |
115 | } | |
116 | } | |
117 | ||
118 | /** | |
119 | * Method to check group organization relationship exist | |
120 | * | |
121 | * @param int $contactId | |
122 | * | |
123 | * @return boolean | |
124 | * @access public | |
125 | * @static | |
126 | */ | |
127 | static function hasGroupAssociated($contactID) { | |
128 | $orgID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_GroupOrganization', | |
129 | $contactID, 'group_id', 'organization_id' | |
130 | ); | |
131 | if ($orgID) { | |
132 | return TRUE; | |
133 | } | |
134 | return FALSE; | |
135 | } | |
136 | ||
137 | /** | |
138 | * Function to delete Group Organization | |
139 | * | |
140 | * @param int $groupOrganizationID group organization id that needs to be deleted | |
141 | * | |
142 | * @return $results no of deleted group organization on success, false otherwise | |
143 | * @access public | |
144 | */ | |
145 | static function deleteGroupOrganization($groupOrganizationID) { | |
146 | $results = NULL; | |
147 | $groupOrganization = new CRM_Contact_DAO_GroupOrganization(); | |
148 | $groupOrganization->id = $groupOrganizationID; | |
149 | ||
150 | $results = $groupOrganization->delete(); | |
151 | ||
152 | return $results; | |
153 | } | |
154 | } | |
155 |