[ 'tb1.name AS category_name' ], 'join_table' => 'categories tb1 ON tb1.id = obj.category_id' ], [ 'field' => [ ], 'join_table' => 'recipe_ingredients tb2 ON tb2.recipe_id = obj.id' ] ); static protected $table_fields = [ 'id' => 'int', 'title' => 'string', 'instruction' => 'string', 'image_url' => 'string', 'estimated_time' => 'int', 'estimated_price' => 'float', 'category_id' => '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, image_url VARCHAR(255) NULL, estimated_time INT NOT NULL, estimated_price INT NOT NULL, category_id 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, FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE );'); return $result; } public function get_price() { return $this->field_estimated_price . '$'; } public function get_status() { return ucfirst($this->field_status); } public function get_image_url() { if ($this->field_image_url) return MEDIA_URL . $this->field_image_url; return null; } public function get_html_instruction(): string { return nl2br(trim($this->field_instruction)); } public function get_time(){ return $this->field_estimated_time . " minutes"; } }