copyValues($params); if ($locationType->find(TRUE)) { CRM_Core_DAO::storeValues($locationType, $defaults); return $locationType; } return NULL; } /** * update the is_active flag in the db * * @param int $id id of the database record * @param boolean $is_active value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * * @access public * @static */ static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_LocationType', $id, 'is_active', $is_active); } /** * retrieve the default location_type * * @param NULL * * @return object The default location type object on success, * null otherwise * @static * @access public */ static function &getDefault() { if (self::$_defaultLocationType == NULL) { $params = array('is_default' => 1); $defaults = array(); self::$_defaultLocationType = self::retrieve($params, $defaults); } return self::$_defaultLocationType; } /* * Get ID of billing location type * @return integer */ /** * @return mixed|null */ static function getBilling() { if (self::$_billingLocationType == NULL) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); self::$_billingLocationType = array_search('Billing', $locationTypes); } return self::$_billingLocationType; } /** * Function to add a Location Type * * @param array $params reference array contains the values submitted by the form * * @internal param array $ids reference array contains the id * * @access public * @static * * @return object */ static function create(&$params) { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE); // action is taken depending upon the mode $locationType = new CRM_Core_DAO_LocationType(); $locationType->copyValues($params); if ($params['is_default']) { $query = "UPDATE civicrm_location_type SET is_default = 0"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } $locationType->save(); return $locationType; } /** * Function to delete location Types * * @param int $locationTypeId ID of the location type to be deleted. * * @access public * @static */ static function del($locationTypeId) { $entity = array('address', 'phone', 'email', 'im'); //check dependencies foreach ($entity as $key) { if ($key == 'im') { $name = strtoupper($key); } else { $name = ucfirst($key); } $baoString = 'CRM_Core_BAO_' . $name; $object = new $baoString(); $object->location_type_id = $locationTypeId; $object->delete(); } $locationType = new CRM_Core_DAO_LocationType(); $locationType->id = $locationTypeId; $locationType->delete(); } }