3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
112 static function getBilling() {
113 if (self
::$_billingLocationType == NULL) {
114 $locationTypes = CRM_Core_PseudoConstant
::locationType();
115 self
::$_billingLocationType = array_search('Billing', $locationTypes);
117 return self
::$_billingLocationType;
121 * Function to add a Location Type
123 * @param array $params reference array contains the values submitted by the form
124 * @param array $ids reference array contains the id
131 static function create(&$params) {
132 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
133 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
134 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
136 // action is taken depending upon the mode
137 $locationType = new CRM_Core_DAO_LocationType();
138 $locationType->copyValues($params);
140 if ($params['is_default']) {
141 $query = "UPDATE civicrm_location_type SET is_default = 0";
142 CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
145 $locationType->save();
146 return $locationType;
150 * Function to delete location Types
152 * @param int $locationTypeId ID of the location type to be deleted.
157 static function del($locationTypeId) {
158 $entity = array('address', 'phone', 'email', 'im');
160 foreach ($entity as $key) {
162 $name = strtoupper($key);
165 $name = ucfirst($key);
167 require_once (str_replace('_', DIRECTORY_SEPARATOR
, 'CRM_Core_DAO_' . $name) . ".php");
168 eval('$object = new CRM_Core_DAO_' . $name . '( );');
169 $object->location_type_id
= $locationTypeId;
173 $locationType = new CRM_Core_DAO_LocationType();
174 $locationType->id
= $locationTypeId;
175 $locationType->delete();