/** * * @param string $name * @param string $type * @param string $forAction * @return Map of Constraint */ public function addConstraint($name, $type, $forAction = null) { $constraint = ConstraintFactory::newConstraint($name, $type, $forAction); // If is readonly, constraint will not be in form (and thus, ignored) if (!$this->isReadonly()) { $this->constraints[] = $constraint; } return $constraint; }
/** * @covers ConstraintFactory::newConstraint * @expectedException Exception * @expectedExceptionMessage Unknown constraint type: allowed */ public function testNewConstraintException() { $type = "allowed"; $actual = \ConstraintFactory::newConstraint("required", $type); $this->assertNull($actual); }
private function extractConstraints() { //check for 'active' searches if (isset($_REQUEST['clearsearch'])) { $this->constraints = new ConstraintChain(); } if (isset($_POST['search'])) { foreach ($_POST['search'] as $fieldname => $search) { $this->constraints[$fieldname][] = ConstraintFactory::Factory($this->model->getField($fieldname), $search); } } if (isset($_POST['quicksearch']) && isset($_POST['quicksearchfield'])) { if ($_POST['submit'] == 'Go') { $this->constraints = new ConstraintChain(); } $model = new $this->collection->_doname(); $searchfield = strtolower($_POST['quicksearchfield']); $search = '%' . strtolower($_POST['quicksearch']) . '%'; $cc = new ConstraintChain(); if ($model->getField($searchfield)->type == 'bool') { switch (strtolower($_POST['quicksearch'])) { case "yes": case "true": case "y": case "t": $cc->add(new Constraint($searchfield, '=', 'true')); break; default: $cc->add(new Constraint($searchfield, '=', 'false')); } } else { $cc->add(new Constraint('lower(' . $searchfield . ')', 'LIKE', $search, 'user')); } $this->addConstraintChain($cc); } //clearing the search will revert to a save, if one exists if ($this->use_session && isset($_POST['clearsearch'])) { if (isset($_SESSION['preferences']['savedsearches'][$this->tablename])) { $this->constraints = $_SESSION['preferences']['savedsearches'][$this->tablename]; } else { $this->constraints = new ConstraintChain(); } } //saving sets the current search to be called upon in the future if ($this->use_session && isset($_POST['savesearch'])) { $_SESSION['preferences']['savedsearches'][$this->tablename] = $this->constraints; } if ($this->use_session && count($this->constraints) == 0 && isset($_SESSION['preferences']['savedsearches'][$this->tablename])) { $this->constraints = $_SESSION['preferences']['savedsearches'][$this->tablename]; } //if usercompanyid is a field, then it's always a constraint $model = $this->collection->getModel(); if ($model->isField('usercompanyid') && $this->use_system_company) { $this->addConstraint(new Constraint('usercompanyid', '=', EGS_COMPANY_ID)); } }