aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/WhereStaticQueryComponent.php
blob: becc587ffa4d4cb96232b8450b5209979264cec2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
/**
 * @class WhereStaticQueryComponent
 * A component of a where query where there is no right hand table, rather a static value.
 * @see Query
 */
class WhereStaticQueryComponent extends WhereQueryComponent
{
	/**
	 * A where query.
	 *
	 * @param string $left_table The table on the left of the operator
	 * @param string $left_field The left field
	 * @param string $operator The operator eg "=" or "<"
	 * @param string $value The value
	 * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
	 */
	function __construct($left_table, $left_field, $operator, $value, $link_operator = "and")
	{
		global $CONFIG;

		$this->link_operator = sanitise_string($link_operator);
		$this->left_table = $CONFIG->dbprefix . sanitise_string($left_table);
		$this->left_field = sanitise_string($left_field);
		$this->operator = sanitise_string($operator);
		if (is_numeric($value))
			$this->value = (int)$value;
		else
			$this->value = "'".sanitise_string($value)."'";
	}

	/**
	 * Return the SQL without the link operator.
	 */
	public function toStringNoLink()
	{
		return "{$this->left_table }.{$this->left_field} {$this->operator} {$this->value}";
	}
}