aboutsummaryrefslogtreecommitdiff
path: root/engine/classes/WhereSetQueryComponent.php
blob: b5fe439a0a471559aa11edab3f759a28cf862844 (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
40
41
<?php
/**
 * @class WhereSetQueryComponent
 * A where query that may contain other where queries (in brackets).
 * @author Curverider Ltd
 * @see Query
 */
class WhereSetQueryComponent extends WhereQueryComponent
{
	/**
	 * Construct a subset of wheres.
	 *
	 * @param array $wheres An array of WhereQueryComponent
	 * @param string $link_operator How this where clause links with the previous clause, eg. "and" "or"
	 */
	function __construct(array $wheres, $link_operator = "and")
	{
		$this->link_operator = sanitise_string($link_operator);
		$this->wheres = $wheres;
	}

	public function toStringNoLink()
	{
		$cnt = 0;
		$string = " (";
		foreach ($this->wheres as $where) {
			if (!($where instanceof WhereQueryComponent))
				throw new DatabaseException(elgg_echo('DatabaseException:WhereSetNonQuery'));

			if (!$cnt)
				$string.= $where->toStringNoLink();
			else
				$string.=" $where ";

			$cnt ++;
		}
		$string .= ")";

		return $string;
	}
}