<?php

namespace Modules\Posts\Models;

use CodeIgniter\Model;

class PostBlockItemsModel extends Model
{

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

    protected $allowedFields = ['block_id', 'item_type', 'title', 'icon', 'value', 'photo', 'caption', 'link', 'description', 'ordering', 'status'];

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

    public function singleBlockItem($id)
    {
      $builder = $this->db->table('post_block_items');
      $builder->select('post_block_items.*, post_blocks.post_id, posts.alias as post_alias ')
              ->join('post_blocks', 'post_blocks.id=post_block_items.block_id', 'left')
              ->join('posts', 'posts.id=post_blocks.post_id', 'left')
              ->where('post_block_items.id', $id);
      return $result = $builder->get()->getRow();
    }


}