<?php

namespace Modules\Sliders\Models;

use CodeIgniter\Model;

class SlidersModel extends Model
{

  protected $table = 'slider';
    protected $primaryKey = 'id';

    protected $allowedFields = ['title', 'alias', 'photo', 'description', 'extra_1', 'extra_2', 'extra_3', 'extra_4', 'category_id', 'link_text', 'link', 'link_2_text', 'link_2', 'background-img', 'ordering', 'status', 'access',  'created_by', 'updated_at', 'updated_by'];

    protected $returnType     = 'array';
    protected $useTimestamps  = true;
    protected $useSoftDeletes = true;
    
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';

    //Get all Post Categories
    public function getAll()
    {
      $builder = $this->db->table('slider as s');
      $builder->select('s.*, sc.name as category_name');
      $builder->join('slider_category as sc', 'sc.id=s.category_id');
      $builder->where('s.deleted_at', null);
      $builder->orderBy('ordering', 'ASC');
		  $result = $builder->get()->getResult();
		  return $result;
    }
    //Get all Post Categories
    public function getHomeSlides()
    {
      $builder = $this->db->table('slider as s');
      $builder->select('s.*, sc.name as category_name');
      $builder->join('slider_category as sc', 'sc.id=s.category_id');
      $builder->where('s.deleted_at', null);
      $builder->where('access', 'Public');
      $builder->where('status', 'Published');
      $builder->orderBy('ordering', 'ASC');
		  $result = $builder->get()->getResult();
		  return $result;
    }


}
