private function prepareResult($all, $errors) { $result = array(); $allCount = sizeof($all); if ($allCount > 0) { $count = (int) $this->settings->getCountOfPosts(); $count = $count > $allCount ? $allCount : $count; usort($all, array($this, 'compareByTime')); $result = array_slice($all, 0, $count); } $response = array('id' => (int) $this->settings->getId(), 'items' => $result, 'errors' => $errors); return json_encode($response); }