<?php

/**
 * Class that operate on table 'restauranttable'. Database Mysql.
 *
 * @author: http://phpdao.com
 * @date: 2018-05-16 11:38
 */
class RestauranttableMySqlExtDAO extends RestauranttableMySqlDAO {

    public function insertWithId($restauranttable) {
        $sql = 'INSERT INTO restauranttable (id, hallid, name, beingUsed, userId, sysdate, del) VALUES (?, ?, ?, ?, ?, ?, ?)';
        $sqlQuery = new SqlQuery($sql);

        $sqlQuery->setNumber($restauranttable->id);
        $sqlQuery->setNumber($restauranttable->hallid);
        $sqlQuery->set($restauranttable->name);
        $sqlQuery->setNumber($restauranttable->beingUsed);
        $sqlQuery->setNumber($restauranttable->userId);
        $sqlQuery->set($restauranttable->sysdate);
        $sqlQuery->setNumber($restauranttable->del);

        $id = $this->executeInsert($sqlQuery);
        $restauranttable->id = $id;
        return $id;
    }

    public function countTables() {
        $sql = 'SELECT count(id)
                FROM restauranttable where del=0 ';
        $sqlQuery = new SqlQuery($sql);
        return $this->querySingleResult($sqlQuery);
    }

    public function queryAllEX($queryString) {
        $sql = 'SELECT restauranttable.*,restauranthall.name as hallName,restauranthall.hallPrice,restauranthall.hallUsers
            FROM restauranttable
            left join restauranthall on restauranthall.id = restauranttable.hallid
            where 1
            ' . $queryString . '
            order by restauranthall.id asc,restauranttable.id asc';
        //echo $sql;
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

    public function updateBeingUsed($beingUsed, $id) {
        $sql = 'UPDATE restauranttable SET beingUsed = ' . $beingUsed . ' WHERE id =  ' . $id . '';
        $sqlQuery = new SqlQuery($sql);
        return $this->executeUpdate($sqlQuery);
    }

    public function gettableIds($search, $hallId) {
        $sql = 'SELECT id,name FROM restauranttable WHERE del = 0 and  name like "%' . $search . '%" ';
        if ($hallId > 0) {
            $sql.=" and hallid = $hallId ";
        }
        $sqlQuery = new SqlQuery($sql);
        return $this->getList($sqlQuery);
    }

}

?>