Pommo_Rules::getLegal PHP Method

getLegal() public static method

returns an array of logics. Array key correlates to field_id.
public static getLegal ( &$group, $fields )
    public static function getLegal(&$group, $fields)
    {
        $c = array();
        $legalities = array('checkbox' => array('true', 'false'), 'multiple' => array('is', 'not'), 'text' => array('is', 'not'), 'date' => array('is', 'not', 'greater', 'less'), 'number' => array('is', 'not', 'greater', 'less'), 'comment' => array());
        foreach ($fields as $field) {
            $c[$field['id']] = $legalities[$field['type']];
        }
        if (empty($group['rules'])) {
            return $c;
        }
        // subtract illogical selections from $c
        foreach ($group['rules'] as $rule) {
            if (!isset($c[$rule['field_id']])) {
                continue;
            }
            // create reference to this field's legalities
            $l =& $c[$rule['field_id']];
            switch ($rule['logic']) {
                case 'true':
                case 'false':
                    // if rule is true or false, field cannot be ANYTHING else
                    unset($l[array_search('true', $l)]);
                    unset($l[array_search('false', $l)]);
                    break;
                case 'is':
                case 'not':
                    unset($l[array_search('not', $l)]);
                    unset($l[array_search('is', $l)]);
                    break;
                case 'greater':
                    unset($l[array_search('greater', $l)]);
                    break;
                case 'less':
                    unset($l[array_search('less', $l)]);
                    break;
            }
        }
        foreach ($c as $key => $val) {
            if (empty($val)) {
                unset($c[$key]);
            }
        }
        return $c;
    }

Usage Example

Example #1
0
$view = new Pommo_Template();
$view->assign('returnStr', _('Groups Page'));
// Initialize page state with default values overriden by those held in $_REQUEST
$state =& Pommo_Api::stateInit('groups_edit', array('group' => 0), $_REQUEST);
$groups = Pommo_Groups::get();
$fields = Pommo_Fields::get();
$group =& $groups[$state['group']];
if (empty($group)) {
    Pommo::redirect('subscribers_groups.php');
}
$rules = Pommo_Sql::sortRules($group['rules']);
$rules['and'] = Pommo_Sql::sortLogic($rules['and']);
$rules['or'] = Pommo_Sql::sortLogic($rules['or']);
foreach ($rules as $key => $a) {
    if ($key == 'include' || $key == 'exclude') {
        foreach ($a as $k => $gid) {
            $rules[$key][$k] = $groups[$gid]['name'];
        }
    }
}
$view->assign('fields', $fields);
$view->assign('legalFieldIDs', Pommo_Rules::getLegal($group, $fields));
$view->assign('legalGroups', Pommo_Rules::getLegalGroups($group, $groups));
$view->assign('group', $group);
$view->assign('logicNames', Pommo_Rules::getEnglish());
$view->assign('rules', $rules);
$view->assign('tally', Pommo_Groups::tally($group));
$view->assign('ruleCount', count($rules['and']) + count($rules['or']) + count($rules['include']) + count($rules['exclude']));
$view->assign('getURL', $_SERVER['PHP_SELF'] . '?group_id=' . $group['id']);
$view->assign('t_include', Pommo::_T('INCLUDE'));
$view->display('admin/subscribers/groups_edit');
All Usage Examples Of Pommo_Rules::getLegal