3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2016
33 class CRM_Contact_BAO_GroupOrganization
extends CRM_Contact_DAO_GroupOrganization
{
38 public function __construct() {
39 parent
::__construct();
43 * Takes an associative array and creates a groupOrganization object.
45 * @param array $params
46 * (reference ) an assoc array of name/value pairs.
48 * @return CRM_Contact_DAO_GroupOrganization
50 public static function add(&$params) {
51 $formattedValues = array();
52 self
::formatValues($params, $formattedValues);
53 $dataExists = self
::dataExists($formattedValues);
57 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
58 $groupOrganization->copyValues($formattedValues);
59 // we have ensured we have group_id & organization_id so we can do a find knowing that
60 // this can only find a matching record
61 $groupOrganization->find(TRUE);
62 $groupOrganization->save();
63 return $groupOrganization;
69 * @param array $params
70 * (reference ) an assoc array of name/value pairs.
71 * @param array $formatedValues
72 * (reference ) an assoc array of name/value pairs.
74 public static function formatValues(&$params, &$formatedValues) {
75 if (!empty($params['group_organization'])) {
76 $formatedValues['id'] = $params['group_organization'];
79 if (!empty($params['group_id'])) {
80 $formatedValues['group_id'] = $params['group_id'];
83 if (!empty($params['organization_id'])) {
84 $formatedValues['organization_id'] = $params['organization_id'];
89 * Check if there is data to create the object.
91 * @param array $params
92 * (reference ) an assoc array of name/value pairs.
96 public static function dataExists($params) {
97 // return if no data present
98 if (!empty($params['organization_id']) && !empty($params['group_id'])) {
105 * @param int $groupID
108 public static function retrieve($groupID, &$defaults) {
109 $dao = new CRM_Contact_DAO_GroupOrganization();
110 $dao->group_id
= $groupID;
111 if ($dao->find(TRUE)) {
112 $defaults['group_organization'] = $dao->id
;
113 $defaults['organization_id'] = $dao->organization_id
;
118 * Method to check group organization relationship exist.
120 * @param int $contactID
124 public static function hasGroupAssociated($contactID) {
125 $orgID = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_GroupOrganization',
126 $contactID, 'group_id', 'organization_id'
135 * Delete Group Organization.
137 * @param int $groupOrganizationID
138 * Group organization id that needs to be deleted.
141 * no of deleted group organization on success, false otherwise
143 public static function deleteGroupOrganization($groupOrganizationID) {
145 $groupOrganization = new CRM_Contact_DAO_GroupOrganization();
146 $groupOrganization->id
= $groupOrganizationID;
148 $results = $groupOrganization->delete();