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 * Fetch object based on array of properties
53 * @param array $params (reference ) an assoc array of name/value pairs
54 * @param array $defaults (reference ) an assoc array to hold the flattened values
56 * @return CRM_Core_BAO_LocaationType object on success, null otherwise
60 static function retrieve(&$params, &$defaults) {
61 $locationType = new CRM_Core_DAO_LocationType();
62 $locationType->copyValues($params);
63 if ($locationType->find(TRUE)) {
64 CRM_Core_DAO
::storeValues($locationType, $defaults);
71 * Update the is_active flag in the db
73 * @param int $id id of the database record
74 * @param boolean $is_active value we want to set the is_active field
76 * @return Object DAO object on sucess, null otherwise
81 static function setIsActive($id, $is_active) {
82 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_LocationType', $id, 'is_active', $is_active);
86 * Retrieve the default location_type
90 * @return object The default location type object on success,
95 static function &getDefault() {
96 if (self
::$_defaultLocationType == NULL) {
97 $params = array('is_default' => 1);
99 self
::$_defaultLocationType = self
::retrieve($params, $defaults);
101 return self
::$_defaultLocationType;
105 * Get ID of billing location type
111 static function getBilling() {
112 if (self
::$_billingLocationType == NULL) {
113 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
114 self
::$_billingLocationType = array_search('Billing', $locationTypes);
116 return self
::$_billingLocationType;
120 * Add a Location Type
122 * @param array $params reference array contains the values submitted by the form
129 static function create(&$params) {
130 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
131 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
132 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
134 // action is taken depending upon the mode
135 $locationType = new CRM_Core_DAO_LocationType();
136 $locationType->copyValues($params);
138 if ($params['is_default']) {
139 $query = "UPDATE civicrm_location_type SET is_default = 0";
140 CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
143 $locationType->save();
144 return $locationType;
148 * Delete location Types
150 * @param int $locationTypeId ID of the location type to be deleted.
155 static function del($locationTypeId) {
156 $entity = array('address', 'phone', 'email', 'im');
158 foreach ($entity as $key) {
160 $name = strtoupper($key);
163 $name = ucfirst($key);
165 $baoString = 'CRM_Core_BAO_' . $name;
166 $object = new $baoString();
167 $object->location_type_id
= $locationTypeId;
171 $locationType = new CRM_Core_DAO_LocationType();
172 $locationType->id
= $locationTypeId;
173 $locationType->delete();