| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
class PluginpkBlogEventTable extends pkBlogItemTable |
|---|
| 6 |
{ |
|---|
| 7 |
|
|---|
| 8 |
* Builds the query for blog posts and events based on the request parameters. |
|---|
| 9 |
* |
|---|
| 10 |
* @param Doctrine_Query $q |
|---|
| 11 |
* @param string $tableName This is going to be either pkBlogPost or pkBlogEvent |
|---|
| 12 |
* @return Doctrrin_Query $q |
|---|
| 13 |
*/ |
|---|
| 14 |
public function buildQuery(sfWebRequest $request, $tableName = 'pkBlogEvent') |
|---|
| 15 |
{ |
|---|
| 16 |
if ($request->getParameter('tag')) |
|---|
| 17 |
{ |
|---|
| 18 |
$q = PluginTagTable::getObjectTaggedWithQuery($tableName, $request->getParameter('tag'), null, array('nb_common_tag' => 1)); |
|---|
| 19 |
} |
|---|
| 20 |
else |
|---|
| 21 |
{ |
|---|
| 22 |
$q = Doctrine_Query::create()->from($tableName.' a'); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
if ($request->getParameter('search')) |
|---|
| 26 |
{ |
|---|
| 27 |
$q = Doctrine::getTable($tableName)->addSearchQuery($q, $request->getParameter('search')); |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
$q = Doctrine::getTable($tableName)->addDateRangeQuery($request, $q); |
|---|
| 31 |
|
|---|
| 32 |
$rootAlias = $q->getRootAlias(); |
|---|
| 33 |
|
|---|
| 34 |
if ($request->getParameter('cat')) |
|---|
| 35 |
{ |
|---|
| 36 |
$q->innerJoin($rootAlias.'.Category c WITH c.slug = ? ', $request->getParameter('cat')); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
$q->addWhere($q->getRootAlias().'.published = ?', true); |
|---|
| 40 |
|
|---|
| 41 |
$q->orderBy($rootAlias.'.start_date asc'); |
|---|
| 42 |
|
|---|
| 43 |
return $q; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
public function addDateRangeQuery(sfWebRequest $request, Doctrine_Query $q = null) |
|---|
| 47 |
{ |
|---|
| 48 |
if (!$q) |
|---|
| 49 |
{ |
|---|
| 50 |
$q = $this->createQuery('e'); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
$rootAlias = $q->getRootAlias(); |
|---|
| 54 |
|
|---|
| 55 |
$q->addWhere($rootAlias.'.start_date >= ?', $request->getParameter('year', date('Y')).'-'.$request->getParameter('month', 1).'-'.$request->getParameter('day', 1).' 0:00:00') |
|---|
| 56 |
->addWhere($rootAlias.'.start_date <= ?', $request->getParameter('year', date('Y')).'-'.$request->getParameter('month', 12).'-'.$request->getParameter('day', 31).' 23:59:59'); |
|---|
| 57 |
|
|---|
| 58 |
return $q; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
public function addUpcomingEventsQuery(Doctrine_Query $q = null) |
|---|
| 62 |
{ |
|---|
| 63 |
if (!$q) |
|---|
| 64 |
{ |
|---|
| 65 |
$q = $this->createQuery('e'); |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
$rootAlias = $q->getRootAlias(); |
|---|
| 69 |
|
|---|
| 70 |
$q->addWhere($rootAlias.'.published = ?', true) |
|---|
| 71 |
->addWhere($rootAlias.'.start_date > ?', date('Y-m-d')) |
|---|
| 72 |
->orderBy($rootAlias.'.start_date, '. $rootAlias .'.start_time'); |
|---|
| 73 |
|
|---|
| 74 |
return $q; |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
public function getLuceneIndex() |
|---|
| 78 |
{ |
|---|
| 79 |
return pkZendSearch::getLuceneIndex($this); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
public function getLuceneIndexFile() |
|---|
| 83 |
{ |
|---|
| 84 |
return pkZendSearch::getLuceneIndexFile($this); |
|---|
| 85 |
} |
|---|
| 86 |
|
|---|
| 87 |
public function searchLucene($luceneQuery) |
|---|
| 88 |
{ |
|---|
| 89 |
return pkZendSearch::searchLucene($this, $luceneQuery); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
public function searchLuceneWithScores($luceneQuery) |
|---|
| 93 |
{ |
|---|
| 94 |
return pkZendSearch::searchLuceneWithScores($this, $luceneQuery); |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
public function rebuildLuceneIndex() |
|---|
| 98 |
{ |
|---|
| 99 |
return pkZendSearch::rebuildLuceneIndex($this); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
public function optimizeLuceneIndex() |
|---|
| 103 |
{ |
|---|
| 104 |
return pkZendSearch::optimizeLuceneIndex($this); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
public function addSearchQuery(Doctrine_Query $q = null, $luceneQuery) |
|---|
| 108 |
{ |
|---|
| 109 |
return pkZendSearch::addSearchQuery($this, $q, $luceneQuery, null); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
public function addSearchQueryWithScores(Doctrine_Query $q = null, $luceneQuery, &$scores) |
|---|
| 113 |
{ |
|---|
| 114 |
return pkZendSearch::addSearchQueryWithScores($this, $q, $luceneQuery, null, $scores); |
|---|
| 115 |
} |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|