class PostService
{
public function findPosts($params = [])
{
$postsCriteria = new CDbCriteria;
if (!empty($params['active'])) {
$postsCriteria->addColumnCondition(['active' => '1']);
}
if (!empty($params['author_id'])) {
$postsCriteria->addColumnCondition(['author_id' => $params['author_id']]);
}
if (!empty($params['order'])) {
switch ($params['order']) {
case 'time_send': $order = 'send_date';
break;
case 'time_edit': $order = 'edit_date';
break;
default: $order = 'id';
}
$postsCriteria->order = $order.' ASC';
}
return PostService::model()->findAll($postsCriteria);
}
}