function applySimpleSearch() { $search = array(); foreach ($this->options as $string) { @(list($k, $id) = explode('-', $string, 2)); $search[$k][] = $id == 'all' ? 'all' : intval($id); } $queries = array(); // union these queries with $this->query $this->queryDescription = array(); foreach ($search as $k => $items) { if ($k == 'all') { $q = new Am_Query_User(); $q->addWhere("IFNULL(u.unsubscribed,0)=0"); $queries = array($q); $this->queryDescription = array(___("All Users")); break; } switch ($k) { case 'aff': $q = new Am_Query_User(); $q->addWhere("IFNULL(u.unsubscribed,0)=0"); $q->addWhere("is_affiliate>0"); $queries[] = $q; $this->queryDescription[] = ___("All Affiliates"); break; case 'active': case 'expired': $q = new Am_Query_User(); $q->addWhere("IFNULL(u.unsubscribed,0)=0"); $product_ids = in_array('all', $items) ? null : $items; $q->add(new Am_Query_User_Condition_HaveSubscriptionTo($product_ids, $k == 'expired' ? User::STATUS_EXPIRED : User::STATUS_ACTIVE)); $queries[] = $q; $this->queryDescription[] = ($k == 'expired' ? ___("Expired Users") : ___("Active Users")) . ($product_ids ? " " . ___("of products") . " " . join(",", $product_ids) : null); break; case 'newsletter': if (Am_Di::getInstance()->modules->isEnabled('newsletter')) { $q = new Am_Query_User(); $q->addWhere("IFNULL(u.unsubscribed,0)=0"); $q->add(new Am_Query_User_Condition_SubscribedToNewsletter($items)); $queries[] = $q; $this->queryDescription[] = ___("Users subscribed to Newsletter Threads #") . join(',', $items); } break; } } if (@$search['guest'] || @$search['newsletter']) { if (Am_Di::getInstance()->modules->isEnabled('newsletter')) { $q = new Am_Query(new NewsletterGuestTable(), 'g'); if ($queries) { $fields = Am_Di::getInstance()->userTable->getFields(true); $q->clearFields(); $guestFields = array('name_f', 'name_l', 'email'); foreach ($fields as $k) { $q->addField(in_array($k, $guestFields) ? $k : '(NULL)', $k); } } $this->queryDescriptionGuest = ___("All Guests"); if (!@$search['guest'] && @$search['newsletter']) { $ids = join(',', $search['newsletter']); $q->innerJoin('?_newsletter_guest_subscription', 'gs', "gs.guest_id=g.guest_id AND list_id IN ({$ids})"); $this->queryDescriptionGuest = ___("Guests having subscription to newsletters %s", $ids); } $queries[] = $q; } } if ($queries) { $this->query = array_shift($queries); foreach ($queries as $q) { $this->query->addUnion($q); } } else { $this->query->addWhere('0=1'); } $this->queryDescription = join(' ,also ', $this->queryDescription); }
function applySimpleSearch() { $search = array(); foreach ($this->options as $string) { @(list($k, $id) = explode('-', $string, 2)); $search[$k][] = $id == 'all' ? 'all' : intval($id); } $queries = array(); // union these queries with $this->query $this->queryDescription = array(); foreach ($search as $k => $items) { if ($k == 'all') { $q = new Am_Query_User(); $q->addWhere("u.unsubscribed=0"); $queries = array($q); $this->queryDescription = array(___("All Users")); break; } switch ($k) { case 'aff': $q = new Am_Query_User(); $q->addWhere("u.unsubscribed=0"); $q->addWhere("is_affiliate>0"); $queries[] = $q; $this->queryDescription[] = ___("All Affiliates"); break; case 'active': case 'expired': $q = new Am_Query_User(); $q->addWhere("u.unsubscribed=0"); $product_ids = in_array('all', $items) ? null : $items; if (!$product_ids) { $q->addWhere("u.status=" . ($k == 'expired' ? User::STATUS_EXPIRED : User::STATUS_ACTIVE)); } else { $q->add(new Am_Query_User_Condition_HaveSubscriptionTo($product_ids, $k == 'expired' ? User::STATUS_EXPIRED : User::STATUS_ACTIVE)); } $queries[] = $q; $this->queryDescription[] = ($k == 'expired' ? ___("Expired Users") : ___("Active Users")) . ($product_ids ? " " . ___("of products") . " " . join(",", $product_ids) : null); break; case 'newsletter': if (Am_Di::getInstance()->modules->isEnabled('newsletter')) { $q = new Am_Query_User(); $q->addWhere("u.unsubscribed=0"); $q->add(new Am_Query_User_Condition_SubscribedToNewsletter($items)); $queries[] = $q; $this->queryDescription[] = ___("Users subscribed to Newsletter Threads #") . join(',', $items); } break; } } if ($queries) { $this->query = array_shift($queries); foreach ($queries as $q) { $this->query->addUnion($q); } } else { $this->query->addWhere('0=1'); } $this->queryDescription = join(' ,also ', $this->queryDescription); }