+
+ /**
+ * Write nested AND/OR criteria
+ * @param array $criteria
+ * @return \pq\Query\Writer
+ */
+ function criteria(array $criteria) {
+ if ((list($left, $right) = each($criteria))) {
+ $this->write("(");
+ if (is_array($right)) {
+ $this->criteria($right);
+ } else {
+ $this->write("(", $left, $this->param($right), ")");
+ }
+ while ((list($left, $right) = each($criteria))) {
+ $this->write(is_int($left) && is_array($right) ? "OR" : "AND");
+ if (is_array($right)) {
+ $this->criteria($right);
+ } else {
+ $this->write("(", $left, $this->param($right), ")");
+ }
+ }
+ $this->write(")");
+ }
+ return $this;
+ }