<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

namespace Kufer\Web\Classes\Db\SQLBuilders;

class DeleteQueryBuilder extends \QueryBuilder
{
  
  public $table;

  
  public $where;

  protected function getSQLString()
  {
    assert(!is_null($this->table));
    if (is_null($this->where) || trim($this->where) === '') {
      return ''; 
    }

    return 'DELETE FROM ' . $this->table . ' WHERE ' . $this->where;
  }

  public function deleteFrom(string $table)
  {
    $this->table = $table;

    return $this;
  }

  
  public function where($sql)
  {
    $this->where = $sql . ' ';

    return $this;
  }

  
  public function addToWhere($sql)
  {
    if (trim($sql) != '') {
      $this->where .= $sql . ' ';
    }

    return $this;
  }
}