45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
namespace Lycoreco\Apps\Recipes\Models;
|
|
|
|
use Lycoreco\Includes\Model\BaseModel;
|
|
|
|
class RecipeModel extends BaseModel
|
|
{
|
|
public $field_title;
|
|
public $field_instruction;
|
|
public $field_estimated_time;
|
|
public $field_estimated_price;
|
|
public $field_category_id;
|
|
public $field_author_id;
|
|
public $field_status;
|
|
public $field_created_at;
|
|
|
|
static protected $table_name = 'recipes';
|
|
static protected $table_fields = [
|
|
'id' => 'int',
|
|
'title' => 'string',
|
|
'instruction' => 'string',
|
|
'estimated_time' => 'int',
|
|
'estimated_price' => 'int',
|
|
'author_id' => 'int',
|
|
'status' => 'string',
|
|
'created_at' => 'DateTime'
|
|
];
|
|
public static function init_table()
|
|
{
|
|
$result = db_query('CREATE TABLE ' . static::$table_name . ' (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
title VARCHAR(255) NOT NULL,
|
|
instruction TEXT NOT NULL,
|
|
estimated_time INT NOT NULL,
|
|
estimated_price INT NOT NULL,
|
|
author_id INT NOT NULL,
|
|
status VARCHAR(20) NOT NULL CHECK (status IN (\'publish\', \'pending\')),
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE
|
|
);');
|
|
return $result;
|
|
}
|
|
} |