3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 class CRM_Core_BAO_LocationType
extends CRM_Core_DAO_LocationType
{
22 * Static holder for the default LT.
25 public static $_defaultLocationType = NULL;
26 public static $_billingLocationType = NULL;
31 public function __construct() {
32 parent
::__construct();
36 * Fetch object based on array of properties.
38 * @param array $params
39 * (reference ) an assoc array of name/value pairs.
40 * @param array $defaults
41 * (reference ) an assoc array to hold the flattened values.
43 * @return CRM_Core_BAO_LocaationType|null
44 * object on success, null otherwise
46 public static function retrieve(&$params, &$defaults) {
47 $locationType = new CRM_Core_DAO_LocationType();
48 $locationType->copyValues($params);
49 if ($locationType->find(TRUE)) {
50 CRM_Core_DAO
::storeValues($locationType, $defaults);
57 * Update the is_active flag in the db.
60 * Id of the database record.
61 * @param bool $is_active
62 * Value we want to set the is_active field.
65 * true if we found and updated the object, else false
67 public static function setIsActive($id, $is_active) {
68 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_LocationType', $id, 'is_active', $is_active);
72 * Retrieve the default location_type.
75 * The default location type object on success,
78 public static function &getDefault() {
79 if (self
::$_defaultLocationType == NULL) {
80 $params = ['is_default' => 1];
82 self
::$_defaultLocationType = self
::retrieve($params, $defaults);
84 return self
::$_defaultLocationType;
88 * Get ID of billing location type.
92 public static function getBilling() {
93 if (self
::$_billingLocationType == NULL) {
94 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', [], 'validate');
95 self
::$_billingLocationType = array_search('Billing', $locationTypes);
97 return self
::$_billingLocationType;
101 * Add a Location Type.
103 * @param array $params
104 * Reference array contains the values submitted by the form.
109 public static function create(&$params) {
110 if (empty($params['id'])) {
111 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
112 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
113 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
116 $locationType = new CRM_Core_DAO_LocationType();
117 $locationType->copyValues($params);
118 if (!empty($params['is_default'])) {
119 $query = "UPDATE civicrm_location_type SET is_default = 0";
120 CRM_Core_DAO
::executeQuery($query);
123 $locationType->save();
124 return $locationType;
128 * Delete location Types.
130 * @param int $locationTypeId
131 * ID of the location type to be deleted.
134 public static function del($locationTypeId) {
135 $entity = ['address', 'phone', 'email', 'im'];
137 foreach ($entity as $key) {
139 $name = strtoupper($key);
142 $name = ucfirst($key);
144 $baoString = 'CRM_Core_BAO_' . $name;
145 $object = new $baoString();
146 $object->location_type_id
= $locationTypeId;
150 $locationType = new CRM_Core_DAO_LocationType();
151 $locationType->id
= $locationTypeId;
152 $locationType->delete();