<?php
namespace Lycoreco\Apps\Recipes\Models;

use Lycoreco\Includes\Model\BaseModel;

class CategoryModel extends BaseModel
{
    public $field_name;
    
    static protected $search_fields = ['obj.name'];
    static protected $table_name = 'categories';
    static protected $table_fields = [
        'id'            => 'int',
        'name'          => 'string',
    ];
    public static function init_table()
    {
        $result = db_query('CREATE TABLE ' . static::$table_name . ' (
            id INT AUTO_INCREMENT PRIMARY KEY,

            name VARCHAR(255) NOT NULL
        );');
        return $result;
    }

    public static function get_cat_values() 
    {
        $cat_list = self::filter(array());
        $result = array();
        foreach($cat_list as $cat) {
            $result[] = [ $cat->get_id(), $cat->field_name ];
        }
        return $result;
    }
}