<?php defined('BASEPATH') or exit('No direct script access allowed');

class editor_model extends CI_Model
{

    public $table = 'partner';

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function findById($editorId) {
        return $this->db->where('idx', $editorId)->get($this->table)->row();
    }

    public function findAll() {
        return $this->db->from($this->table.  ' l');
    }

    public function findByCategoryId($categoryId) {
        return $this->db->from($this->table. ' p')->where_in('category_idx', $categoryId)->where('p.is_del', 'N')
        ->select('p.idx editorId, p.partner_img editorImg, p.main_img editorMainImg, p.partner_name editorName, p.partner_intro editorIntro, p.category_idx categoryId');
    }

    public function getEditors($c, $l) {
        $q = $this->db->query("SELECT 
            `p`.`idx` `editorId`,
            `p`.`partner_img` `editorImg`,
            `p`.`main_img` `editorMainImg`,
            `p`.`partner_name` `editorName`,
            `p`.`partner_intro` `editorIntro`,
            `p`.`category_idx` `categoryId`
        FROM
            `partner` `p`
        WHERE
            `category_idx` IN ($c)
                AND `p`.`is_del` = 'N'
        LIMIT $l");
        return $q->result();
    }

}
