Commit 9a265785 authored by colemanw's avatar colemanw Committed by GitHub

Merge pull request #11045 from mepps/CRM-20304

CRM-20304 Bug fixes to Alphabetize options
parents 7a7009e6 71bdf27c
......@@ -108,6 +108,47 @@ class CRM_Custom_Page_Option extends CRM_Core_Page {
return self::$_actionLinks;
}
/**
* Alphabetize multiple option values
*
* @return void
*/
public function alphabetize() {
$optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField',
$this->_fid,
'option_group_id'
);
$query = "
SELECT id, label
FROM civicrm_option_value
WHERE option_group_id = %1";
$params = array(
1 => array($optionGroupID, 'Integer'),
);
$dao = CRM_Core_DAO::executeQuery($query, $params);
$optionValue = array();
while ($dao->fetch()) {
$optionValue[$dao->id] = $dao->label;
}
asort($optionValue, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL);
$i = 1;
foreach ($optionValue as $key => $_) {
$clause[] = "WHEN $key THEN $i";
$i++;
}
$when = implode(' ', $clause);
$sql = "
UPDATE civicrm_option_value
SET weight = CASE id
$when
END
WHERE option_group_id = %1";
$dao = CRM_Core_DAO::executeQuery($sql, $params);
}
/**
* Browse all custom group fields.
*
......@@ -167,7 +208,6 @@ WHERE option_group_id = %1";
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
$this->browse();
}
/**
......@@ -222,7 +262,7 @@ WHERE option_group_id = %1";
$this, FALSE, 0
);
// what action to take ?
// take action in addition to default browse ?
if (($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD |
CRM_Core_Action::VIEW | CRM_Core_Action::DELETE
)
......@@ -232,9 +272,11 @@ WHERE option_group_id = %1";
// no browse for edit/update/view
$this->edit($action);
}
else {
$this->browse();
elseif ($action & CRM_Core_Action::MAP) {
$this->alphabetize();
}
$this->browse();
// Call the parents run method
return parent::run();
}
......
......@@ -498,7 +498,7 @@
settings = $el.data('popup-settings') || {},
formData = false;
settings.dialog = settings.dialog || {};
if (e.isDefaultPrevented() || !CRM.config.ajaxPopupsEnabled || !url || $el.is(exclude)) {
if (e.isDefaultPrevented() || !CRM.config.ajaxPopupsEnabled || !url || $el.is(exclude + ', .open-inline, .open-inline-noreturn')) {
return;
}
// Sized based on css class
......
......@@ -157,6 +157,7 @@
{/literal}
<div class="action-link">
{crmButton q="reset=1&action=map&fid=$fid&gid=$gid" class="action-item open-inline-noreturn" icon="sort-alpha-asc"}{ts}Alphabetize Options{/ts}{/crmButton}
{crmButton q="reset=1&action=add&fid=$fid&gid=$gid" class="action-item" icon="plus-circle"}{ts}Add Option{/ts}{/crmButton}
{crmButton p="civicrm/admin/custom/group/field" q="reset=1&action=browse&gid=$gid" class="action-item cancel" icon="times"}{ts}Done{/ts}{/crmButton}
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment