<?php
namespace WpBookingEventAdmin\app\models;
defined('_WPBOOKINGEVENT_EXEC') or die;

use WpBookingEvent\Factory;
use WpBookingEvent\Mvc\Model\ModelForm;
use WpBookingEvent\Form\Form;
use WpBookingEvent\Mvc\Model\ModelList;
use WpBookingEvent\Registry\Registry;
class ReviewsModel extends ModelList
{
    /**
     * @var string
     */
    public $context = "reviews";
    /**
     * @var string
     */
    public $table_name = "review";

    public function sorting($list)
    {
        foreach ($list as $item){
            $item=(object)$item;
            $item_sorting=[
                'id'=> $item->id,
                'ordering'=>$item->ordering
            ];
            if(!parent::save($item_sorting)){
                return false;
            }
        }
        return true;
    }
    public function getList()
    {
        $query = $this->db->getQuery(true);
        $query->select("review.*")
            ->from($this->getTableName() . ' AS review')
            ->leftJoin($this->getTableName('service') . ' AS service ON service.id =review.service_id')
            ->select('service.name as service_name');
        return $this->db->setQuery($query)->loadObjectList();
    }
}
