X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fnewsletter.inc.php;h=1097f59defa66ab0729934584ae0ffc6fc42a5f9;hb=b9518dc770273f43f2b37305f11446be4aacef86;hp=0ee1423d9989675f2038701f8678fade1236caf0;hpb=0fd5be9929ec59aefa4f2d0ec7ed66e29a5daf3b;p=platal.git diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 0ee1423..1097f59 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -47,6 +47,11 @@ class NewsLetter const GROUP_AX = 'AX'; const GROUP_EP = 'Ecole'; + // Searches on mutiple fields + const SEARCH_ALL = 'all'; + const SEARCH_TITLE = 'title'; + + // {{{ Constructor, NewsLetter retrieval (forGroup, getAll) public function __construct($id) @@ -251,6 +256,63 @@ class NewsLetter } } + /** Returns a list of either issues or articles corresponding to the search. + * @p $search The searched pattern. + * @p $field The fields where to search, if none given, search in all possible fields. + * @return The list of object found. + */ + public function issueSearch($search, $field, $user) + { + $search = XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $search); + if ($field == self::SEARCH_ALL) { + $where = '(title ' . $search . ' OR mail_title ' . $search . ' OR head ' . $search . ' OR signature ' . $search . ')'; + } elseif ($field == self::SEARCH_TITLE) { + $where = '(title ' . $search . ' OR mail_title ' . $search . ')'; + } else { + $where = $field . $search; + } + $list = XDB::fetchColumn('SELECT DISTINCT(id) + FROM newsletter_issues + WHERE nlid = {?} AND state = \'sent\' AND ' . $where . ' + ORDER BY date DESC', + $this->id); + + $issues = array(); + foreach ($list as $id) { + $issue = new NLIssue($id, $this, false); + if ($issue->checkUser($user)) { + $issues[] = $issue; + } + } + return $issues; + } + + public function articleSearch($search, $field, $user) + { + $search = XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $search); + if ($field == self::SEARCH_ALL) { + $where = '(a.title ' . $search . ' OR a.body ' . $search . ' OR a.append ' . $search . ')'; + } else { + $where = 'a.' . $field . $search; + } + $list = XDB::fetchAllAssoc('SELECT i.short_name, a.aid, i.id, a.title + FROM newsletter_art AS a + INNER JOIN newsletter_issues AS i ON (a.id = i.id) + WHERE i.nlid = {?} AND i.state = \'sent\' AND ' . $where . ' + GROUP BY a.id, a.aid + ORDER BY i.date DESC, a.aid', + $this->id); + + $articles = array(); + foreach ($list as $item) { + $issue = new NLIssue($item['id'], $this, false); + if ($issue->checkUser($user)) { + $articles[] = $item; + } + } + return $articles; + } + // }}} // {{{ Subscription related function @@ -558,6 +620,7 @@ class NLIssue $this->nl = new NewsLetter($issue['nlid']); } $this->id = $id; + $this->nlid = $issue['nlid']; $this->shortname = $issue['short_name']; $this->date = $issue['date']; $this->send_before = $issue['send_before'];