3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
35 class CRM_Core_BAO_LocationType
extends CRM_Core_DAO_LocationType
{
38 * static holder for the default LT
40 static $_defaultLocationType = NULL;
41 static $_billingLocationType = NULL;
46 function __construct() {
47 parent
::__construct();
51 * Takes a bunch of params that are needed to match certain criteria and
52 * retrieves the relevant objects. Typically the valid params are only
53 * contact_id. We'll tweak this function to be more full featured over a period
54 * of time. This is the inverse function of create. It also stores all the retrieved
55 * values in the default array
57 * @param array $params (reference ) an assoc array of name/value pairs
58 * @param array $defaults (reference ) an assoc array to hold the flattened values
60 * @return object CRM_Core_BAO_LocaationType object on success, null otherwise
64 static function retrieve(&$params, &$defaults) {
65 $locationType = new CRM_Core_DAO_LocationType();
66 $locationType->copyValues($params);
67 if ($locationType->find(TRUE)) {
68 CRM_Core_DAO
::storeValues($locationType, $defaults);
75 * update the is_active flag in the db
77 * @param int $id id of the database record
78 * @param boolean $is_active value we want to set the is_active field
80 * @return Object DAO object on sucess, null otherwise
85 static function setIsActive($id, $is_active) {
86 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_LocationType', $id, 'is_active', $is_active);
90 * retrieve the default location_type
94 * @return object The default location type object on success,
99 static function &getDefault() {
100 if (self
::$_defaultLocationType == NULL) {
101 $params = array('is_default' => 1);
103 self
::$_defaultLocationType = self
::retrieve($params, $defaults);
105 return self
::$_defaultLocationType;
109 * Get ID of billing location type
115 static function getBilling() {
116 if (self
::$_billingLocationType == NULL) {
117 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
118 self
::$_billingLocationType = array_search('Billing', $locationTypes);
120 return self
::$_billingLocationType;
124 * Function to add a Location Type
126 * @param array $params reference array contains the values submitted by the form
128 * @internal param array $ids reference array contains the id
135 static function create(&$params) {
136 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
137 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
138 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
140 // action is taken depending upon the mode
141 $locationType = new CRM_Core_DAO_LocationType();
142 $locationType->copyValues($params);
144 if ($params['is_default']) {
145 $query = "UPDATE civicrm_location_type SET is_default = 0";
146 CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
149 $locationType->save();
150 return $locationType;
154 * Function to delete location Types
156 * @param int $locationTypeId ID of the location type to be deleted.
161 static function del($locationTypeId) {
162 $entity = array('address', 'phone', 'email', 'im');
164 foreach ($entity as $key) {
166 $name = strtoupper($key);
169 $name = ucfirst($key);
171 $baoString = 'CRM_Core_BAO_' . $name;
172 $object = new $baoString();
173 $object->location_type_id
= $locationTypeId;
177 $locationType = new CRM_Core_DAO_LocationType();
178 $locationType->id
= $locationTypeId;
179 $locationType->delete();