123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php namespace App\Models;
- use CodeIgniter\Database\ConnectionInterface;
- use CodeIgniter\Model;
- class ProductModel extends Model
- {
- protected $table = 'products';
- protected $primaryKey = 'Id';
- protected $allowedFields = ['image','imageTitle','slug','category','info','price'];
- protected $limit;
- protected $offset;
- protected $Id;
- protected $imageTitle;
- protected $slug;
- protected $category;
- protected $info;
-
- /*
- $db = \Config\Database::connect();
- $builder = $db->table('products');
- */
-
- public function insertProduct($image,$imageTitle,$slug,$category,$info,$price)
- {
- $data = [
- 'image' => $image,
- 'imageTitle' => $imageTitle,
- 'slug'=> $slug,
- 'category'=>$category,
- 'info'=>$info,
- 'price'=>$price
- ];
- $this->save($data);
- }
-
-
- public function getAll()
- {
- return $this->orderBy('Id', 'desc')->findAll();
- }
-
-
-
-
-
-
-
-
-
-
-
- public function getOne($id)
- {
-
- return $this->find($id);
-
- // return $this->asArray()
- // ->where(['Id'=>$id]);
-
- }
-
-
- public function amendProduct($Id,$imageTitle,$slug,$category,$info,$price)
-
-
- {
-
-
- $data =[
- 'imageTitle'=>$imageTitle,
- 'slug'=>$slug,
- 'category'=>$category,
- 'info'=>$info,
- 'price'=>$price
- ];
- $logic= $this->update($Id,$data);
- return $logic;
-
- }
-
- public function deleteOne($id)
- {
- $this->where('Id',$id )->delete();
- //need to get name image associated with blog and unlink it
-
- return True;
-
-
- }
- public function getCountByCategory($category)
-
- {
- $db = \Config\Database::connect();
- $builder = $db->table('products');
-
- $query = $builder->where('category',$category)->countAllResults();
- return $query;
- /*
- $query = $db->query("SELECT COUNT(*) FROM products where category=$category ");
- $count = $query->getRowArray();
- return $count;
- */
-
- }
-
- public function useCategory($category)
- {
- return $this->where('category', $category)
- ->findAll();
- }
- }
|