/**
 * Delete uf field.
 *
 * @param array $params
 *
 * @throws API_Exception
 *
 * @return array
 */
function civicrm_api3_uf_field_delete($params)
{
    $fieldId = $params['id'];
    $ufGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $fieldId, 'uf_group_id');
    if (!$ufGroupId) {
        throw new API_Exception('Invalid value for field_id.');
    }
    $result = CRM_Core_BAO_UFField::del($fieldId);
    $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroupId, TRUE);
    CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroupId, $fieldsType);
    return civicrm_api3_create_success($result, $params);
}
Example #2
0
 /**
  * Delete the profile Group.
  *
  * @param int $id
  *   Profile Id.
  *
  * @return bool
  *
  */
 public static function del($id)
 {
     //check whether this group contains  any profile fields
     $profileField = new CRM_Core_DAO_UFField();
     $profileField->uf_group_id = $id;
     $profileField->find();
     while ($profileField->fetch()) {
         CRM_Core_BAO_UFField::del($profileField->id);
     }
     //delete records from uf join table
     $ufJoin = new CRM_Core_DAO_UFJoin();
     $ufJoin->uf_group_id = $id;
     $ufJoin->delete();
     //delete profile group
     $group = new CRM_Core_DAO_UFGroup();
     $group->id = $id;
     $group->delete();
     return 1;
 }
Example #3
0
 /**
  * Delete profile field given a custom field.
  *
  * @param int $customFieldId
  *   ID of the custom field to be deleted.
  *
  * @return void
  *
  */
 public static function delUFField($customFieldId)
 {
     //find the profile id given custom field id
     $ufField = new CRM_Core_DAO_UFField();
     $ufField->field_name = "custom_" . $customFieldId;
     $ufField->find();
     while ($ufField->fetch()) {
         //enable/ disable profile
         CRM_Core_BAO_UFField::del($ufField->id);
     }
 }
Example #4
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     $ids = array('uf_group' => $this->_gid);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
         $deleted = CRM_Core_BAO_UFField::del($this->_id);
         //update group_type every time. CRM-3608
         if ($this->_gid && $deleted) {
             //get the profile type.
             $groupType = 'null';
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid);
             if (!empty($fieldsType)) {
                 $groupType = implode(',', $fieldsType);
             }
             //set group type
             CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType);
         }
         CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'));
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     if ($params['visibility'] == 'User and User Admin Only') {
         $params['is_searchable'] = 0;
         $params['in_selector'] = 0;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['uf_field'] = $this->_id;
     }
     //check for duplicate fields
     if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
         CRM_Core_Session::setStatus(ts('The selected field was not added. It already exists in this profile.'));
         return;
     } else {
         $ufField = CRM_Core_BAO_UFField::add($params, $ids);
         $name = $this->_selectFields[$ufField->field_name];
         //reset other field is searchable and in selector settings, CRM-4363
         if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership'))) {
             CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid);
         }
         $config =& CRM_Core_Config::singleton();
         $showBestResult = false;
         if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) {
             // get state or country field weight if exists
             $field = 'state_province';
             if ($ufField->field_name == 'state_province') {
                 $field = 'country';
             }
             $ufFieldDAO =& new CRM_Core_DAO_UFField();
             $ufFieldDAO->field_name = $field;
             $ufFieldDAO->location_type_id = $ufField->location_type_id;
             $ufFieldDAO->uf_group_id = $ufField->uf_group_id;
             if ($ufFieldDAO->find(true)) {
                 if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) {
                     $showBestResult = true;
                 } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) {
                     $showBestResult = true;
                 }
             }
         }
         //update group_type every time. CRM-3608
         if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) {
             //get the profile type.
             $groupType = 'null';
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid);
             if (!empty($fieldsType)) {
                 $groupType = implode(',', $fieldsType);
             }
             //set group type
             CRM_Core_DAO::setFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'group_type', $groupType);
         }
         CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved.', array(1 => $name)));
     }
     $buttonName = $this->controller->getButtonName();
     $session =& CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         CRM_Core_Session::setStatus(ts(' You can add another profile field.'));
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"));
     } else {
         $session->set('showBestResult', $showBestResult);
     }
 }
Example #5
0
/**
 * Delete uf field
 *  
 * @param $ufField Object  Valid uf_field object that to be deleted
 *
 * @return true on successful delete or return error
 *
 * @access public
 *
 */
function crm_delete_uf_field($ufField)
{
    _crm_initialize();
    $fieldId = $ufField->id;
    if (!isset($fieldId)) {
        return _crm_error("parameter {$fieldId}  is not set ");
    }
    require_once 'CRM/Core/BAO/UFField.php';
    return CRM_Core_BAO_UFField::del($fieldId);
}
Example #6
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 function postProcess()
 {
     if ($this->_action & CRM_CORE_ACTION_DELETE) {
         CRM_Core_BAO_UFField::del($this->_id);
         CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'));
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     $ids = array();
     if ($this->_action & CRM_CORE_ACTION_UPDATE) {
         $ids['uf_field'] = $this->_id;
     }
     $ids['uf_group'] = $this->_gid;
     //check for duplicate fields
     if (CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
         CRM_Core_Session::setStatus(ts('The selected field was not added. It already exists in this profile.'));
         return;
     } else {
         $ufField = CRM_Core_BAO_UFField::add($params, $ids);
         $name = $this->_selectFields[$ufField->field_name];
         CRM_Core_Session::setStatus(ts('Your civicrm profile field "%1" has been saved.', array(1 => $name)));
     }
 }
Example #7
0
 /**
  * Process the form.
  *
  * @return void
  */
 public function postProcess()
 {
     $ids = array('uf_group' => $this->_gid);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         CRM_Utils_Weight::delWeight('CRM_Core_DAO_UFField', $this->_id, $fieldValues);
         $deleted = CRM_Core_BAO_UFField::del($this->_id);
         //update group_type every time. CRM-3608
         if ($this->_gid && $deleted) {
             //get the profile type.
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE);
             CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
         }
         CRM_Core_Session::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success');
         return;
     }
     // store the submitted values in an array
     $params = $this->controller->exportValues('Field');
     if ($params['visibility'] == 'User and User Admin Only') {
         $params['is_searchable'] = $params['in_selector'] = 0;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ids['uf_field'] = $this->_id;
     }
     $name = NULL;
     if (isset($params['field_name'][1]) && isset($this->_selectFields[$params['field_name'][1]])) {
         // we dont get a name for a html formatting element
         $name = $this->_selectFields[$params['field_name'][1]];
     }
     //Hack for Formatting Field Name
     if ($params['field_name'][0] == 'Formatting') {
         $params['field_name'][1] = 'formatting_' . rand(1000, 9999);
     }
     //check for duplicate fields
     if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField::duplicateField($params, $ids)) {
         CRM_Core_Session::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error');
         return;
     } else {
         $params['weight'] = CRM_Core_BAO_UFField::autoWeight($params);
         $ufField = CRM_Core_BAO_UFField::add($params, $ids);
         //reset other field is searchable and in selector settings, CRM-4363
         if ($this->_hasSearchableORInSelector && in_array($ufField->field_type, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) {
             CRM_Core_BAO_UFField::resetInSelectorANDSearchable($this->_gid);
         }
         $config = CRM_Core_Config::singleton();
         $showBestResult = FALSE;
         if (in_array($ufField->field_name, array('country', 'state_province')) && count($config->countryLimit) > 1) {
             // get state or country field weight if exists
             $field = 'state_province';
             if ($ufField->field_name == 'state_province') {
                 $field = 'country';
             }
             $ufFieldDAO = new CRM_Core_DAO_UFField();
             $ufFieldDAO->field_name = $field;
             $ufFieldDAO->location_type_id = $ufField->location_type_id;
             $ufFieldDAO->uf_group_id = $ufField->uf_group_id;
             if ($ufFieldDAO->find(TRUE)) {
                 if ($field == 'country' && $ufFieldDAO->weight > $ufField->weight) {
                     $showBestResult = TRUE;
                 } elseif ($field == 'state_province' && $ufFieldDAO->weight < $ufField->weight) {
                     $showBestResult = TRUE;
                 }
             }
         }
         //update group_type every time. CRM-3608
         if ($this->_gid && is_a($ufField, 'CRM_Core_DAO_UFField')) {
             // get the profile type.
             $fieldsType = CRM_Core_BAO_UFGroup::calculateGroupType($this->_gid, TRUE);
             CRM_Core_BAO_UFGroup::updateGroupTypes($this->_gid, $fieldsType);
         }
         CRM_Core_Session::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.', array(1 => $name, 2 => $this->_title)), ts('Profile Field Saved'), 'success');
     }
     $buttonName = $this->controller->getButtonName();
     $session = CRM_Core_Session::singleton();
     if ($buttonName == $this->getButtonName('next', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field/add', "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"));
         $session->set('showBestResult', $showBestResult);
     }
 }
/**
 * Delete uf field
 *
 * @param $fieldId int  Valid uf_field id that to be deleted
 *
 * @return true on successful delete or return error
 *
 * @access public
 *
 */
function civicrm_uf_field_delete($fieldId)
{
    _civicrm_initialize();
    if (!isset($fieldId)) {
        return civicrm_create_error("provide a valid fieldId.");
    }
    require_once 'CRM/Core/BAO/UFField.php';
    return CRM_Core_BAO_UFField::del($fieldId);
}