123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php namespace App\Models;
- use CodeIgniter\Database\ConnectionInterface;
- use CodeIgniter\Model;
- class BlogModel extends Model
- {
- protected $table = 'blog';
- protected $primaryKey = 'Id';
- protected $allowedFields = ['title','article','image','slug','date'];
- protected $limit;
- protected $offset;
- protected $Id;
- protected $title;
- protected $article;
- protected $slug;
- public function getArticle($slug)
- {
- return $this->asArray()
- ->where(['slug' => $slug])
- ->first();
- }
-
- public function count()
- {
-
- return $this->countAll();
-
- }
- public function getOneToDel($id)
- {
-
- return $this->find($id);
-
- // return $this->asArray()
- // ->where(['Id'=>$id]);
-
- }
- public function getOne()
- {
-
- $this->limit=1;
- $this->offset=0;
- return $this->orderBy('Id', 'desc')->findAll($this->limit, $this->offset);
- }
- public function getThree()
- {
-
- $this->limit=3;
- $this->offset=0;
- return $this->orderBy('Id', 'desc')->findAll($this->limit, $this->offset);
- }
- public function getSome()
- {
- $this->limit=2;
- $this->offset=1;
- return $this->orderBy('Id', 'desc')->findAll($this->limit, $this->offset);
- }
- public function getAll()
- {
- return $this->orderBy('Id', 'desc')->findAll();
- }
- public function insertBlog($title,$article,$image,$slug,$date)
- {
- $data = [
- 'title' => $title,
- 'article' => $article,
- 'image'=> $image,
- 'slug'=>$slug,
- 'date'=>$date
- ];
- $this->save($data);
- return True;
- }
- public function deleteOne($id)
- {
- $this->where('Id',$id )->delete();
- //need to get name image associated with blog and unlink it
-
- return True;
-
-
- }
- public function amendBlog($blogId,$title,$article,$slug)
-
-
- {
-
- $this->Id= $blogId;
- $this->title= $title;
- $this->article = $article;
- $this->slug=$slug;
- $data =[
- 'title'=>$this->title,
- 'article'=>$this->article,
- 'slug'=>$this->slug
- ];
- $logic= $this->update($this->Id,$data);
- return $logic;
-
- }
- public function isEmpty()
- {
- $db = \Config\Database::connect("default");
-
- $query = $db->query("SELECT * FROM blog order by Id DESC LIMIT 3");
-
-
-
-
-
- $count = $query->getRowArray();
- return $count;
-
- }
- }
|