Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20304 Bug fixes to Alphabetize options #11045

Merged
merged 6 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions CRM/Custom/Page/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,47 @@ public static function &actionLinks() {
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.
*
Expand Down Expand Up @@ -167,7 +208,6 @@ public function edit($action) {
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
$this->browse();
}

/**
Expand Down Expand Up @@ -222,7 +262,7 @@ public function run() {
$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
)
Expand All @@ -232,9 +272,11 @@ public function run() {
// 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();
}
Expand Down
2 changes: 1 addition & 1 deletion js/crm.ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions templates/CRM/Custom/Page/Option.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down