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

use Lycoreco\Includes\Model\BaseModel;

class IngredientModel extends BaseModel
{
    public $field_name;
    public $field_unit_name;

    static protected $search_fields = ['obj.name'];
    static protected $table_name = 'ingredients';

    static protected $table_fields = [
        'id'            => 'int',
        'name'         => 'string',
        'unit_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,
            unit_name VARCHAR(20) NULL
        );');
        return $result;
    }
    public static function get_ing_values() 
    {
        $ing_list = self::filter(array());
        $result = array();
        foreach($ing_list as $ing) {
            $result[] = [ $ing->get_id(), $ing->field_name . ' ('. $ing->field_unit_name .')'  ];
        }
        return $result;
    }
}