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
17 class CRM_Core_BAO_LocationType
extends CRM_Core_DAO_LocationType
{
20 * Static holder for the default LT.
23 public static $_defaultLocationType = NULL;
24 public static $_billingLocationType = NULL;
29 public function __construct() {
30 parent
::__construct();
34 * Fetch object based on array of properties.
36 * @param array $params
37 * (reference ) an assoc array of name/value pairs.
38 * @param array $defaults
39 * (reference ) an assoc array to hold the flattened values.
41 * @return CRM_Core_BAO_LocaationType|null
42 * object on success, null otherwise
44 public static function retrieve(&$params, &$defaults) {
45 $locationType = new CRM_Core_DAO_LocationType();
46 $locationType->copyValues($params);
47 if ($locationType->find(TRUE)) {
48 CRM_Core_DAO
::storeValues($locationType, $defaults);
55 * Update the is_active flag in the db.
58 * Id of the database record.
59 * @param bool $is_active
60 * Value we want to set the is_active field.
63 * true if we found and updated the object, else false
65 public static function setIsActive($id, $is_active) {
66 return CRM_Core_DAO
::setFieldValue('CRM_Core_DAO_LocationType', $id, 'is_active', $is_active);
70 * Retrieve the default location_type.
73 * The default location type object on success,
76 public static function &getDefault() {
77 if (self
::$_defaultLocationType == NULL) {
78 $params = ['is_default' => 1];
80 self
::$_defaultLocationType = self
::retrieve($params, $defaults);
82 return self
::$_defaultLocationType;
86 * Get ID of billing location type.
90 public static function getBilling() {
91 if (self
::$_billingLocationType == NULL) {
92 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', [], 'validate');
93 self
::$_billingLocationType = array_search('Billing', $locationTypes);
95 return self
::$_billingLocationType;
99 * Add a Location Type.
101 * @param array $params
102 * Reference array contains the values submitted by the form.
107 public static function create(&$params) {
108 if (empty($params['id'])) {
109 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
110 $params['is_default'] = CRM_Utils_Array
::value('is_default', $params, FALSE);
111 $params['is_reserved'] = CRM_Utils_Array
::value('is_reserved', $params, FALSE);
114 $locationType = new CRM_Core_DAO_LocationType();
115 $locationType->copyValues($params);
116 if (!empty($params['is_default'])) {
117 $query = "UPDATE civicrm_location_type SET is_default = 0";
118 CRM_Core_DAO
::executeQuery($query);
121 $locationType->save();
122 return $locationType;
126 * Delete location Types.
128 * @param int $locationTypeId
129 * ID of the location type to be deleted.
132 public static function del($locationTypeId) {
133 $entity = ['address', 'phone', 'email', 'im'];
135 foreach ($entity as $key) {
137 $name = strtoupper($key);
140 $name = ucfirst($key);
142 $baoString = 'CRM_Core_BAO_' . $name;
143 $object = new $baoString();
144 $object->location_type_id
= $locationTypeId;
148 $locationType = new CRM_Core_DAO_LocationType();
149 $locationType->id
= $locationTypeId;
150 $locationType->delete();