Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/controller/HeraldRuleController.php
Show First 20 Lines • Show All 421 Lines • ▼ Show 20 Lines | private function setupEditorBehavior( | ||||
foreach ($rule->getActions() as $action) { | foreach ($rule->getActions() as $action) { | ||||
$action_name = $action->getAction(); | $action_name = $action->getAction(); | ||||
if (empty($action_map[$action_name])) { | if (empty($action_map[$action_name])) { | ||||
$action_map[$action_name] = pht('<Unknown Action "%s">', $action_name); | $action_map[$action_name] = pht('<Unknown Action "%s">', $action_name); | ||||
} | } | ||||
} | } | ||||
$group_map = array(); | |||||
foreach ($field_map as $field_key => $field_name) { | |||||
$group_key = $adapter->getFieldGroupKey($field_key); | |||||
$group_map[$group_key][$field_key] = $field_name; | |||||
} | |||||
$field_groups = HeraldFieldGroup::getAllFieldGroups(); | |||||
$groups = array(); | |||||
foreach ($group_map as $group_key => $options) { | |||||
asort($options); | |||||
$field_group = idx($field_groups, $group_key); | |||||
if ($field_group) { | |||||
$group_label = $field_group->getGroupLabel(); | |||||
$group_order = $field_group->getSortKey(); | |||||
} else { | |||||
$group_label = nonempty($group_key, pht('Other')); | |||||
$group_order = 'Z'; | |||||
} | |||||
$groups[] = array( | |||||
'label' => $group_label, | |||||
'options' => $options, | |||||
'order' => $group_order, | |||||
); | |||||
} | |||||
$groups = array_values(isort($groups, 'order')); | |||||
$config_info = array(); | $config_info = array(); | ||||
$config_info['fields'] = $groups; | $config_info['fields'] = $this->getFieldGroups($adapter, $field_map); | ||||
$config_info['conditions'] = $all_conditions; | $config_info['conditions'] = $all_conditions; | ||||
$config_info['actions'] = $action_map; | $config_info['actions'] = $this->getActionGroups($adapter, $action_map); | ||||
$config_info['valueMap'] = array(); | $config_info['valueMap'] = array(); | ||||
foreach ($field_map as $field => $name) { | foreach ($field_map as $field => $name) { | ||||
try { | try { | ||||
$field_conditions = $adapter->getConditionsForField($field); | $field_conditions = $adapter->getConditionsForField($field); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$field_conditions = array(HeraldAdapter::CONDITION_UNCONDITIONALLY); | $field_conditions = array(HeraldAdapter::CONDITION_UNCONDITIONALLY); | ||||
} | } | ||||
Show All 15 Lines | foreach ($field_map as $field => $fname) { | ||||
} | } | ||||
$config_info['values'][$field][$condition] = $value_key; | $config_info['values'][$field][$condition] = $value_key; | ||||
} | } | ||||
} | } | ||||
$config_info['rule_type'] = $rule->getRuleType(); | $config_info['rule_type'] = $rule->getRuleType(); | ||||
foreach ($config_info['actions'] as $action => $name) { | foreach ($action_map as $action => $name) { | ||||
try { | try { | ||||
$value_key = $adapter->getValueTypeForAction( | $value_key = $adapter->getValueTypeForAction( | ||||
$action, | $action, | ||||
$rule->getRuleType()); | $rule->getRuleType()); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$value_key = new HeraldEmptyFieldValue(); | $value_key = new HeraldEmptyFieldValue(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | private function loadRulesThisRuleMayDependUpon(HeraldRule $rule) { | ||||
} | } | ||||
// A rule can not depend upon itself. | // A rule can not depend upon itself. | ||||
unset($all_rules[$rule->getID()]); | unset($all_rules[$rule->getID()]); | ||||
return $all_rules; | return $all_rules; | ||||
} | } | ||||
private function getFieldGroups(HeraldAdapter $adapter, array $field_map) { | |||||
$group_map = array(); | |||||
foreach ($field_map as $field_key => $field_name) { | |||||
$group_key = $adapter->getFieldGroupKey($field_key); | |||||
$group_map[$group_key][$field_key] = $field_name; | |||||
} | |||||
return $this->getGroups( | |||||
$group_map, | |||||
HeraldFieldGroup::getAllFieldGroups()); | |||||
} | |||||
private function getActionGroups(HeraldAdapter $adapter, array $action_map) { | |||||
$group_map = array(); | |||||
foreach ($action_map as $action_key => $action_name) { | |||||
$group_key = $adapter->getActionGroupKey($action_key); | |||||
$group_map[$group_key][$action_key] = $action_name; | |||||
} | |||||
return $this->getGroups( | |||||
$group_map, | |||||
HeraldActionGroup::getAllActionGroups()); | |||||
} | |||||
private function getGroups(array $item_map, array $group_list) { | |||||
assert_instances_of($group_list, 'HeraldGroup'); | |||||
$groups = array(); | |||||
foreach ($item_map as $group_key => $options) { | |||||
asort($options); | |||||
$group_object = idx($group_list, $group_key); | |||||
if ($group_object) { | |||||
$group_label = $group_object->getGroupLabel(); | |||||
$group_order = $group_object->getSortKey(); | |||||
} else { | |||||
$group_label = nonempty($group_key, pht('Other')); | |||||
$group_order = 'Z'; | |||||
} | |||||
$groups[] = array( | |||||
'label' => $group_label, | |||||
'options' => $options, | |||||
'order' => $group_order, | |||||
); | |||||
} | |||||
return array_values(isort($groups, 'order')); | |||||
} | |||||
} | } |