public function testCreateCustomValue() { $this->_populateOptionAndCustomGroup(); $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml(); $count = 0; foreach ($customFieldDataType as $dataType => $label) { switch ($dataType) { case 'Country': case 'StateProvince': $this->foreignKeyChecksOff(); case 'String': case 'Link': case 'Int': case 'Float': case 'Money': case 'Date': case 'Boolean': //Based on the custom field data-type choose desired SQL operators(to test with) and basic $type if (in_array($dataType, array('String', 'Link'))) { $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'); $type = 'string'; } elseif ($dataType == 'Boolean') { $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL'); $type = 'boolean'; } else { if ($dataType == 'Country') { $type = 'country'; } elseif ($dataType == 'StateProvince') { $type = 'state_province'; } elseif ($dataType == 'ContactReference') { $type = 'contact'; } elseif ($dataType == 'Date') { $type = 'date'; } else { $type = $dataType == 'Int' ? 'integer' : 'number'; } $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'); } //Create custom field of $dataType and html-type $html foreach ($dataToHtmlTypes[$count] as $html) { $params = array('custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "{$dataType} - {$html}", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL); if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) { $params += array('option_group_id' => $this->optionGroup[$type]['id']); } $customField = $this->customFieldCreate($params); //Now test with $validSQLOperator SQL operators against its custom value(s) $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperators, $type); } $count++; break; default: // skipping File data-type $count++; break; } } }
/** * Function to set variables up before form is built * * @param null * * @return void * @access public */ function preProcess() { require_once 'CRM/Core/BAO/CustomField.php'; if (!$GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataTypeKeys']) { $GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataTypeKeys'] = array_keys(CRM_Core_BAO_CustomField::dataType()); $GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataTypeValues'] = array_values(CRM_Core_BAO_CustomField::dataType()); } $this->_gid = CRM_Utils_Request::retrieve('gid', $this); $this->_id = CRM_Utils_Request::retrieve('id', $this); if ($GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataToLabels'] == null) { $GLOBALS['_CRM_CUSTOM_FORM_FIELD']['_dataToLabels'] = array(array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio'), 'CheckBox' => ts('CheckBox'), 'Multi-Select' => ts('Multi-Select')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('TextArea' => ts('TextArea')), array('Date' => ts('Select Date')), array('Radio' => ts('Radio')), array('StateProvince' => ts('Select State/Province')), array('Country' => ts('Select Country'))); } }
public function testCreateCustomValue() { $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml(); $count = 0; foreach ($customFieldDataType as $dataType => $label) { switch ($dataType) { case 'Date': case 'StateProvince': case 'String': case 'Link': case 'Int': case 'Float': case 'Money': if (in_array($dataType, array('String', 'Link'))) { $validSQLOperator = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'); $type = 'string'; } else { if ($dataType == 'Country') { $type == 'country'; } elseif ($dataType == 'StateProvince') { $type = 'state_province'; } elseif ($dataType == 'ContactReference') { $type = 'contact'; } elseif ($dataType == 'Date') { $type = 'date'; } else { $type = $dataType == 'Int' ? 'integer' : 'number'; } $validSQLOperator = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'); } foreach ($dataToHtmlTypes[$count] as $html) { $params = array('custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "{$dataType} - {$html}", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL); if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference'))) { $params += array('option_group_id' => $this->optionGroup[$type]['id']); } $customField = $this->customFieldCreate($params); $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperator, $type); } $count++; break; default: //TODO: Test case of Country fields remain as it throws foreign key contraint ONLY in test environment $count++; break; } } }
/** * Set variables up before form is built. * * @return void */ public function preProcess() { if (!self::$_dataTypeKeys) { self::$_dataTypeKeys = array_keys(CRM_Core_BAO_CustomField::dataType()); self::$_dataTypeValues = array_values(CRM_Core_BAO_CustomField::dataType()); } if (!self::$_dataToHTML) { self::$_dataToHTML = CRM_Core_BAO_CustomField::dataToHtml(); } //custom field id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_values = array(); //get the values form db if update. if ($this->_id) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomField::retrieve($params, $this->_values); // note_length is an alias for the text_length field $this->_values['note_length'] = CRM_Utils_Array::value('text_length', $this->_values); // custom group id $this->_gid = $this->_values['custom_group_id']; } else { // custom group id $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); } if ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_reserved', 'id')) { CRM_Core_Error::fatal("You cannot add or edit fields in a reserved custom field-set."); } if ($this->_gid) { $url = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } if (self::$_dataToLabels == NULL) { self::$_dataToLabels = array(array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio'), 'CheckBox' => ts('CheckBox'), 'Multi-Select' => ts('Multi-Select'), 'AdvMulti-Select' => ts('Adv Multi-Select (obsolete)'), 'Autocomplete-Select' => ts('Autocomplete-Select')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('TextArea' => ts('TextArea'), 'RichTextEditor' => ts('Rich Text Editor')), array('Date' => ts('Select Date')), array('Radio' => ts('Radio')), array('StateProvince' => ts('Select State/Province'), 'Multi-Select' => ts('Multi-Select State/Province')), array('Country' => ts('Select Country'), 'Multi-Select' => ts('Multi-Select Country')), array('File' => ts('Select File')), array('Link' => ts('Link')), array('ContactReference' => ts('Autocomplete-Select'))); } }
/** * Check for Each data type: loop through available form input types */ public function testCustomFieldCreateAllAvailableFormInputs() { $gid = $this->customGroupCreate(array('extends' => 'Individual', 'title' => 'testAllFormInputs')); $dtype = CRM_Core_BAO_CustomField::dataType(); $htype = CRM_Core_BAO_CustomField::dataToHtml(); $n = 0; foreach ($dtype as $dkey => $dvalue) { foreach ($htype[$n] as $hkey => $hvalue) { //echo $dkey."][".$hvalue."\n"; $this->_loopingCustomFieldCreateTest($this->_buildParams($gid['id'], $hvalue, $dkey)); } $n++; } }
public function testCreateCustomValue() { $this->_populateOptionAndCustomGroup(); $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $dataToHtmlTypes = CRM_Core_BAO_CustomField::dataToHtml(); $count = 0; $optionSupportingHTMLTypes = array('Select', 'Radio', 'CheckBox', 'AdvMulti-Select', 'Autocomplete-Select', 'Multi-Select'); foreach ($customFieldDataType as $dataType => $label) { switch ($dataType) { // case 'Country': // case 'StateProvince': case 'String': case 'Link': case 'Int': case 'Float': case 'Money': case 'Date': case 'Boolean': //Based on the custom field data-type choose desired SQL operators(to test with) and basic $type if (in_array($dataType, array('String', 'Link'))) { $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE', 'IS NOT NULL', 'IS NULL'); $type = 'string'; } elseif ($dataType == 'Boolean') { $validSQLOperators = array('=', '!=', 'IS NOT NULL', 'IS NULL'); $type = 'boolean'; } else { if ($dataType == 'Country') { $type = 'country'; } elseif ($dataType == 'StateProvince') { $type = 'state_province'; } elseif ($dataType == 'ContactReference') { $type = 'contact'; } elseif ($dataType == 'Date') { $type = 'date'; } else { $type = $dataType == 'Int' ? 'integer' : 'number'; } $validSQLOperators = array('=', '!=', 'IN', 'NOT IN', '<=', '>=', '>', '<', 'IS NOT NULL', 'IS NULL'); } //Create custom field of $dataType and html-type $html foreach ($dataToHtmlTypes[$count] as $html) { // per CRM-18568 the like operator does not currently work for fields with options. // the LIKE operator could potentially bypass ACLs (as could IS NOT NULL) and some thought needs to be given // to it. if (in_array($html, $optionSupportingHTMLTypes)) { $validSQLOperators = array_diff($validSQLOperators, array('LIKE', 'NOT LIKE')); } $params = array('custom_group_id' => $this->ids[$type]['custom_group_id'], 'label' => "{$dataType} - {$html}", 'data_type' => $dataType, 'html_type' => $html, 'default_value' => NULL); if (!in_array($html, array('Text', 'TextArea')) && !in_array($dataType, array('Link', 'Date', 'ContactReference', 'Boolean'))) { $params += array('option_group_id' => $this->optionGroup[$type]['id']); } $customField = $this->customFieldCreate($params); //Now test with $validSQLOperator SQL operators against its custom value(s) $this->_testCustomValue($customField['values'][$customField['id']], $validSQLOperators, $type); } $count++; break; default: // skipping File data-type & state province due to caching issues $count++; break; } } }
/** * Function to set variables up before form is built * * @param null * * @return void * @access public */ public function preProcess() { require_once 'CRM/Core/BAO/CustomField.php'; if (!self::$_dataTypeKeys) { self::$_dataTypeKeys = array_keys(CRM_Core_BAO_CustomField::dataType()); self::$_dataTypeValues = array_values(CRM_Core_BAO_CustomField::dataType()); } //custom group id $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); //custom field id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); //get the values form db if update. $this->_values = array(); if ($this->_id) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomField::retrieve($params, $this->_values); } if (self::$_dataToLabels == null) { self::$_dataToLabels = array(array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio'), 'CheckBox' => ts('CheckBox'), 'Multi-Select' => ts('Multi-Select'), 'AdvMulti-Select' => ts('Advanced Multi-Select'), 'Autocomplete-Select' => ts('Autocomplete Select')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('TextArea' => ts('TextArea'), 'RichTextEditor' => 'RichTextEditor'), array('Date' => ts('Select Date')), array('Radio' => ts('Radio')), array('StateProvince' => ts('Select State/Province'), 'Multi-Select' => ts('Multi-Select State/Province')), array('Country' => ts('Select Country'), 'Multi-Select' => ts('Multi-Select Country ')), array('File' => ts('Select File')), array('Link' => ts('Link')), array('ContactReference' => ts('Autocomplete Select'))); } }
/** * Function to set variables up before form is built * * @param null * * @return void * @access public */ public function preProcess() { if (!self::$_dataTypeKeys) { self::$_dataTypeKeys = array_keys(CRM_Core_BAO_CustomField::dataType()); self::$_dataTypeValues = array_values(CRM_Core_BAO_CustomField::dataType()); } if (!self::$_dataToHTML) { self::$_dataToHTML = CRM_Core_BAO_CustomField::dataToHtml(); } //custom group id $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this); if ($this->_gid) { $url = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } //custom field id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); //get the values form db if update. $this->_values = array(); if ($this->_id) { $params = array('id' => $this->_id); CRM_Core_BAO_CustomField::retrieve($params, $this->_values); } if (self::$_dataToLabels == NULL) { self::$_dataToLabels = array(array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio'), 'CheckBox' => ts('CheckBox'), 'Multi-Select' => ts('Multi-Select'), 'AdvMulti-Select' => ts('Advanced Multi-Select'), 'Autocomplete-Select' => ts('Autocomplete Select')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('Text' => ts('Text'), 'Select' => ts('Select'), 'Radio' => ts('Radio')), array('TextArea' => ts('TextArea'), 'RichTextEditor' => 'RichTextEditor'), array('Date' => ts('Select Date')), array('Radio' => ts('Radio')), array('StateProvince' => ts('Select State/Province'), 'Multi-Select' => ts('Multi-Select State/Province')), array('Country' => ts('Select Country'), 'Multi-Select' => ts('Multi-Select Country ')), array('File' => ts('Select File')), array('Link' => ts('Link')), array('ContactReference' => ts('Autocomplete Select'))); } }
/** * Browse all custom group fields. * * @return void */ public function browse() { $resourceManager = CRM_Core_Resources::singleton(); if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) { $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header'); } $customField = array(); $customFieldBAO = new CRM_Core_BAO_CustomField(); // fkey is gid $customFieldBAO->custom_group_id = $this->_gid; $customFieldBAO->orderBy('weight, label'); $customFieldBAO->find(); while ($customFieldBAO->fetch()) { $customField[$customFieldBAO->id] = array(); CRM_Core_DAO::storeValues($customFieldBAO, $customField[$customFieldBAO->id]); $action = array_sum(array_keys($this->actionLinks())); if ($customFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } switch ($customFieldBAO->data_type) { case "String": case "Int": case "Float": case "Money": // if Multi Select field is selected in custom field if ($customFieldBAO->html_type == 'Text') { $action -= CRM_Core_Action::BROWSE; } break; case "ContactReference": case "Memo": case "Date": case "Boolean": case "StateProvince": case "Country": case "File": case "Link": $action -= CRM_Core_Action::BROWSE; break; } $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $customField[$customFieldBAO->id]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id]['data_type']]; $customField[$customFieldBAO->id]['order'] = $customField[$customFieldBAO->id]['weight']; $customField[$customFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $customFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'customField.row.actions', 'CustomField', $customFieldBAO->id); } $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "custom_group_id = {$this->_gid}"; CRM_Utils_Weight::addOrder($customField, 'CRM_Core_DAO_CustomField', 'id', $returnURL, $filter); $this->assign('customField', $customField); }
/** * Browse all custom group fields. * * @param null * * @return void * @access public */ function browse() { require_once 'CRM/Core/BAO/CustomField.php'; $customField = array(); $customFieldBAO =& new CRM_Core_BAO_CustomField(); // fkey is gid $customFieldBAO->custom_group_id = $this->_gid; $customFieldBAO->orderBy('weight, label'); $customFieldBAO->find(); while ($customFieldBAO->fetch()) { $customField[$customFieldBAO->id] = array(); CRM_Core_DAO::storeValues($customFieldBAO, $customField[$customFieldBAO->id]); $action = array_sum(array_keys($this->actionLinks())); if ($customFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } switch ($customFieldBAO->data_type) { case "String": case "Int": case "Float": case "Money": // if Multi Select field is selected in custom field if ($customFieldBAO->html_type == 'Text') { $action -= CRM_Core_Action::BROWSE; } break; case "ContactReference": case "Memo": case "Date": case "Boolean": case "StateProvince": case "Country": case "File": case "Link": $action -= CRM_Core_Action::BROWSE; break; } $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $customField[$customFieldBAO->id]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id]['data_type']]; $customField[$customFieldBAO->id]['order'] = $customField[$customFieldBAO->id]['weight']; $customField[$customFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $customFieldBAO->id, 'gid' => $this->_gid)); } $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "custom_group_id = {$this->_gid}"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($customField, 'CRM_Core_DAO_CustomField', 'id', $returnURL, $filter); $this->assign('customField', $customField); }
/** * Browse all custom group fields. * * @param null * * @return void * @access public */ function browse() { require_once 'CRM/Core/BAO/CustomField.php'; $customField = array(); $customFieldBAO =& new CRM_Core_BAO_CustomField(); // fkey is gid $customFieldBAO->custom_group_id = $this->_gid; $customFieldBAO->orderBy('weight, label'); $customFieldBAO->find(); while ($customFieldBAO->fetch()) { $customField[$customFieldBAO->id] = array(); CRM_Core_DAO::storeValues($customFieldBAO, $customField[$customFieldBAO->id]); $action = array_sum(array_keys($this->actionLinks())); if ($customFieldBAO->is_active) { $action -= CRM_CORE_ACTION_ENABLE; } else { $action -= CRM_CORE_ACTION_DISABLE; } // if Multi Select field is selected in custom field if ($customFieldBAO->data_type == 'String' || $customFieldBAO->data_type == 'Int' || $customFieldBAO->data_type == 'Float' || $customFieldBAO->data_type == 'Money') { if ($customFieldBAO->html_type == 'Text') { $action -= CRM_CORE_ACTION_BROWSE; } } switch ($customFieldBAO->data_type) { case "Memo": $action -= CRM_CORE_ACTION_BROWSE; break; case "Date": $action -= CRM_CORE_ACTION_BROWSE; break; case "Boolean": $action -= CRM_CORE_ACTION_BROWSE; break; case "StateProvince": $action -= CRM_CORE_ACTION_BROWSE; break; case "Country": $action -= CRM_CORE_ACTION_BROWSE; break; } $customFieldDataType = CRM_Core_BAO_CustomField::dataType(); $customField[$customFieldBAO->id]['data_type'] = $customFieldDataType[$customField[$customFieldBAO->id]['data_type']]; $customField[$customFieldBAO->id]['action'] = CRM_Core_Action::formLink(CRM_Custom_Page_Field::actionLinks(), $action, array('id' => $customFieldBAO->id, 'gid' => $this->_gid)); } $this->assign('customField', $customField); }