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