| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
class PluginsfBlogPostFinder extends Dbfinder |
|---|
| 4 |
{ |
|---|
| 5 |
protected $class = 'sfBlogPost'; |
|---|
| 6 |
|
|---|
| 7 |
public function recent() |
|---|
| 8 |
{ |
|---|
| 9 |
$userClass = sfConfig::get('app_sfBlogs_user_class', 'sfGuardUser'); |
|---|
| 10 |
return $this-> |
|---|
| 11 |
innerJoin($userClass)-> |
|---|
| 12 |
with($userClass)-> |
|---|
| 13 |
published()-> |
|---|
| 14 |
orderBy('CreatedAt', 'desc'); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
public function published() |
|---|
| 18 |
{ |
|---|
| 19 |
return $this-> |
|---|
| 20 |
where('IsPublished', true)-> |
|---|
| 21 |
where('PublishedAt', '<=', time()); |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
public function draft() |
|---|
| 25 |
{ |
|---|
| 26 |
return $this-> |
|---|
| 27 |
where('IsPublished', false); |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
public function tagged($tag) |
|---|
| 31 |
{ |
|---|
| 32 |
return $this-> |
|---|
| 33 |
join('sfBlogTag')-> |
|---|
| 34 |
where('sfBlogTag.Tag', $tag); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
public function managedBy($user) |
|---|
| 38 |
{ |
|---|
| 39 |
return $this-> |
|---|
| 40 |
_if(!$user->hasCredential('administrator'))-> |
|---|
| 41 |
join('sfBlog')->join('sfBlogUser')-> |
|---|
| 42 |
where('sfBlogUser.UserId', $user->getGuardUser()->getId())-> |
|---|
| 43 |
_endif(); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
public function whereBlogTitle($strippedTitle) |
|---|
| 47 |
{ |
|---|
| 48 |
return $this-> |
|---|
| 49 |
with('sfBlog')-> |
|---|
| 50 |
where('sfBlog.StrippedTitle', $strippedTitle); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
public function findArchives($blog = null) |
|---|
| 54 |
{ |
|---|
| 55 |
return $this-> |
|---|
| 56 |
published()-> |
|---|
| 57 |
_if($blog)-> |
|---|
| 58 |
relatedTo($blog)-> |
|---|
| 59 |
_endif()-> |
|---|
| 60 |
withColumn('date_format(sfBlogPost.PublishedAt, \'%y%m\')', 'month')-> |
|---|
| 61 |
withColumn('count(Id)', 'count')-> |
|---|
| 62 |
groupBy('month')-> |
|---|
| 63 |
orderBy('month', 'desc')-> |
|---|
| 64 |
find(); |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
public function archived($month) |
|---|
| 68 |
{ |
|---|
| 69 |
return $this-> |
|---|
| 70 |
whereCustom('date_format(sfBlogPost.PublishedAt, \'%%y%%m\') = ?',$month); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
public function filterByText($text) |
|---|
| 74 |
{ |
|---|
| 75 |
$text = trim($text); |
|---|
| 76 |
if ($text == '' || preg_match('/^[\%\*]+$/', $text)) |
|---|
| 77 |
{ |
|---|
| 78 |
return $this; |
|---|
| 79 |
} |
|---|
| 80 |
$text = '%'.trim($text, '*%').'%'; |
|---|
| 81 |
return $this-> |
|---|
| 82 |
where('Title', 'like', $text)-> |
|---|
| 83 |
orWhere('Content', 'like', $text); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
public function filterByBlogId($blogId) |
|---|
| 87 |
{ |
|---|
| 88 |
if ($blogId) |
|---|
| 89 |
{ |
|---|
| 90 |
return $this->where('sfBlogId', $blogId); |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
public function filterbyTag($tag) |
|---|
| 95 |
{ |
|---|
| 96 |
if ($tag) |
|---|
| 97 |
{ |
|---|
| 98 |
return $this-> |
|---|
| 99 |
join('sfBlogTag')-> |
|---|
| 100 |
where('sfBlogTag.Tag', $tag); |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
public function applySort($sorts) |
|---|
| 105 |
{ |
|---|
| 106 |
$sort_column = $sorts['sort']; |
|---|
| 107 |
switch($sort_column) |
|---|
| 108 |
{ |
|---|
| 109 |
case 'blog': |
|---|
| 110 |
case 'author': |
|---|
| 111 |
case 'nb_comments': |
|---|
| 112 |
case 'title': |
|---|
| 113 |
$sort_method = 'orderBy' . sfInflector::camelize($sort_column); |
|---|
| 114 |
$this->$sort_method($sorts['type']); |
|---|
| 115 |
break; |
|---|
| 116 |
case 'default': |
|---|
| 117 |
$this->orderByDate($sorts['type']); |
|---|
| 118 |
break; |
|---|
| 119 |
default: |
|---|
| 120 |
$sort_column = sfInflector::camelize($sort_column); |
|---|
| 121 |
$this->orderBy($sort_column, $sorts['type']); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
return $this; |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
public function findByStrippedTitleAndDate($text, $date) |
|---|
| 128 |
{ |
|---|
| 129 |
return $this-> |
|---|
| 130 |
where('StrippedTitle', $text)-> |
|---|
| 131 |
_if(sfConfig::get('app_sfBlogs_use_date_in_url', false))-> |
|---|
| 132 |
where('PublishedAt', $date)-> |
|---|
| 133 |
_endif()-> |
|---|
| 134 |
findOne(); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
public function orderByTitle($order = 'asc') |
|---|
| 138 |
{ |
|---|
| 139 |
return $this-> |
|---|
| 140 |
withColumn('UPPER(sfBlogPost.Title)', 'UTitle')-> |
|---|
| 141 |
orderBy('UTitle', $order); |
|---|
| 142 |
} |
|---|
| 143 |
|
|---|
| 144 |
public function orderByBlog($order = 'asc') |
|---|
| 145 |
{ |
|---|
| 146 |
return $this-> |
|---|
| 147 |
leftJoin('sfBlog')-> |
|---|
| 148 |
orderBy('sfBlog.Title', $order); |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
public function orderByAuthor($order = 'asc') |
|---|
| 152 |
{ |
|---|
| 153 |
return $this-> |
|---|
| 154 |
leftJoin('sfGuardUser')-> |
|---|
| 155 |
orderBy('sfGuardUser.username', $order); |
|---|
| 156 |
} |
|---|
| 157 |
|
|---|
| 158 |
public function orderByNbComments($order = 'asc') |
|---|
| 159 |
{ |
|---|
| 160 |
return $this-> |
|---|
| 161 |
orderBy('NbComments', $order); |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
public function orderByDate($order = 'asc') |
|---|
| 165 |
{ |
|---|
| 166 |
|
|---|
| 167 |
return $this-> |
|---|
| 168 |
withColumn('IFNULL(sfBlogPost.PublishedAt, sfBlogPost.CreatedAt)', 'date_sort')-> |
|---|
| 169 |
orderBy('date_sort', $order); |
|---|
| 170 |
} |
|---|
| 171 |
} |
|---|