public function get($id = null) { $request = CoreApp::getRequest(); $selectTable = QueryBase::tableizeModelName($this->modelClass); $parsedResources = $this->parseResources($request->getResourceArray()); $queryBase = new QueryBase($this->modelClass); $constraint = new Constraints(); if (empty($id)) { $resourceArray = $request->getResourceArray(); $id = $resourceArray[count($resourceArray) - 1]; } $queryBase->Select(); if (!empty($parsedResources['joins'])) { $joinsArray = array_map("core\\Inflector::tableize", $parsedResources['joins']); $queryBase->Join($joinsArray); } $constraint->term("{$selectTable}" . ".id", "=", $id); if (!empty($parsedResources['constraints'])) { foreach ($parsedResources['constraints'] as $kv) { $table = Inflector::tableize($kv->resource) . ".id"; $value = $kv->value; $constraint->andTerm($table, "=", $value); } } $queryBase->Where($constraint); $sql = $queryBase->getSelect(); $bindValues = $queryBase->getBindValues(); if ($this->query($sql, $bindValues)) { return $this->getResultsSet(); } return false; }
public function check($data, $model, $lax = false) { $result = true; $this->error = ''; $constraints = new Constraints($lax); try { $constraints->validate($data, $model->data); } catch (ValidationException $e) { $this->error = $e->getMessage(); $result = false; } return $result; }
/** * gets the built constraints clause from a constraints instance defined outside of * this method. Sets bound params to constraints to this query. * * @param \core\Constraints $constraint * @return \core\QueryBase */ public function Where(Constraints $constraint) { $constraints = $constraint->getConstraints(); if (!empty($constraints)) { $this->query['WHERE'] = "WHERE " . $constraints; $this->bindings = array_merge($this->bindings, $constraint->getBindings()); } return $this; }