Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Frontend\Models;
- use Common\Model\BaseModel as Model;
- class News extends Model {
- protected $table = 'news';
- protected $key;
- /**
- * @return int
- * @throws \Exception
- */
- public function getCount() {
- $sql = "SELECT * FROM " . parent::PREFIX . $this->table;
- $rows = $this->fetch($sql);
- if ( !$rows ) {
- throw new \Exception("нет новостей");
- }
- return count($rows);
- }
- /**
- * @param $limit
- * @param $offset
- * @return mixed
- * @throws \Exception
- */
- public function allNews( $limit, $offset ) {
- $sql = "SELECT * FROM " . parent::PREFIX . $this->table . " LIMIT {$limit}, {$offset}";
- $rows = $this->fetch($sql);
- if ( !$rows ) {
- throw new \Exception("not find items");
- }
- return $rows;
- }
- /**
- * @param $key
- * @param array $param
- * @return array|string
- * @throws \Exception
- */
- public function getSingle($key, $param = []) {
- $data = [
- "news_url" => $param['news_url']
- ];
- $this->key = $key;
- if( !$rows = parent::findBy($data, "SELECT * FROM " . parent::PREFIX . $this->table . " where {$this->key} = :news_url") ){
- throw new \Exception("Ошибка");
- }
- return $rows;
- }
- /**
- * @param $limit
- * @return mixed
- * @throws \Exception
- */
- public function getNews( $limit ) {
- $sql = "SELECT * FROM " . parent::PREFIX . $this->table . " LIMIT {$limit}";
- $rows = $this->fetch($sql);
- if ( !$rows ) {
- throw new \Exception("not find items");
- }
- return $rows;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement