sortLogic() public static method

returns a logic array
public static sortLogic ( &$rules )
Beispiel #1
0
 public static function groupSQL($group, $tally = false, $status = 1, $filter = false)
 {
     // used to prevent against group include/exclude recursion
     static $groups;
     if (!isset($groups[$group['id']])) {
         $groups[$group['id']] = TRUE;
     }
     global $pommo;
     $dbo =& Pommo::$_dbo;
     $rules = Pommo_Sql::sortRules($group['rules']);
     $ands = Pommo_Sql::getSubQueries(Pommo_Sql::sortLogic($rules['and']));
     $ors = empty($rules['or']) ? array() : Pommo_Sql::getSubQueries(Pommo_Sql::sortLogic($rules['or']));
     $sql = $tally ? 'SELECT count(subscriber_id) ' : 'SELECT subscriber_id ';
     $sql .= "\n            FROM {$dbo->table['subscribers']}\n            WHERE status=" . intval($status);
     $q = FALSE;
     if (!empty($ands)) {
         $sql .= " AND (\n";
         foreach ($ands as $k => $s) {
             if ($k != 0) {
                 $sql .= "\n AND ";
             }
             $sql .= $s;
         }
         foreach ($ors as $s) {
             $sql .= "\n OR {$s}";
         }
         $sql .= "\n)";
         $q = TRUE;
     }
     foreach ($rules['exclude'] as $gid) {
         if (!isset($groups[$gid])) {
             $sql .= "\nAND subscriber_id NOT IN (\n";
             $sql .= Pommo_Sql::groupSQL(current(Pommo_Groups::get(array('id' => $gid))));
             $sql .= "\n)";
         }
         $q = TRUE;
     }
     foreach ($rules['include'] as $gid) {
         if (!isset($groups[$gid])) {
             $sql .= "\n" . ($q ? 'OR' : 'AND') . " subscriber_id IN (\n";
             $sql .= Pommo_Sql::groupSQL(current(Pommo_Groups::get(array('id' => $gid))));
             $sql .= "\n)";
         }
         $q = TRUE;
     }
     // If a filter/search is requested, perform a match
     if (is_array($filter) && !empty($filter['field']) && !empty($filter['string'])) {
         // make MySQL LIKE() compliant
         $filter['string'] = mysql_real_escape_string(addcslashes($filter['string'], '%_'));
         $sql .= is_numeric($filter['field']) ? "\n AND subscriber_id in (select subscriber_id from {$dbo->table['subscriber_data']} WHERE field_id = " . (int) $filter['field'] . " AND value LIKE '%{$filter['string']}%')" : "\n AND " . mysql_real_escape_string($filter['field']) . " LIKE '%{$filter['string']}%'";
     }
     return $sql;
 }
Beispiel #2
0
	SETUP TEMPLATE, PAGE
 *********************************/
require_once Pommo::$_baseDir . 'classes/Pommo_Template.php';
$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']));