function &_BrokenRules() { $brs = new Broken_Rules(); $gs =& GlobalSingleton::GetInstance(); $capThisPersonIsAlreadyAssociatedToThisMovie = $gs->GetText($locale, 'capThisPersonIsAlreadyAssociatedToThisMovie'); $capActorMustHaveCharacterName = $gs->GetText($locale, 'capActorMustHaveCharacterName'); $capNoPerson = $gs->GetText($locale, 'capNoPerson'); $capNoMovie = $gs->GetText($locale, 'capNoMovie'); if ($this->IsNew()) { /*TODO:BUG: Single quotes need to be escaped */ $m2p = new MovieToPerson("movieID = " . $this->MovieID() . " AND " . "personID = " . $this->PersonID() . " AND " . "relationship = '" . $this->Relationship() . "' AND " . "((relationship <> 's') OR (relationship = 's' AND characterName = '" . $this->CharacterName() . "'))"); if (!$m2p->IsEmpty()) { $brs->Add("DUPLICATE_ASSOCIATION", $capThisPersonIsAlreadyAssociatedToThisMovie); } } $brs->Assert('NO_ACTOR', $this->PersonID() == ""); $brs->Assert('NO_MOVIE', $this->MovieID() == ""); $brs->Assert('NO_CHAR_NAME', $capActorMustHaveCharacterName, $this->Relationship() == 's' && $this->CharacterName() == ""); return $brs; }
function &_BrokenRules() { $brs = new Broken_Rules(); $gs =& GlobalSingleton::GetInstance(); if ($this->IsNew()) { $per = new Person("firstName = '" . $this->FirstName() . "' AND " . "lastName = '" . $this->LastName() . "'"); } else { $per = new Person("id != " . $this->ID() . " AND firstName = '" . $this->FirstName() . "' AND " . "lastName = '" . $this->LastName() . "'"); } if (!$per->IsEmpty()) { $capThisPersonAleadyExistsInTheDatabase = $gs->GetText($locale, 'capThisPersonAleadyExistsInTheDatabase'); $brs->Add("DUPLICATE_PERSON", $capThisPersonAleadyExistsInTheDatabase); } return $brs; }
function &_BrokenRules() { $brs = new Broken_Rules(); $brs->Assert('SYMBOL_START_WITH_PIPE', 'Symbols can\'t start with pipes', substr($this->Symbol(), 0, 1) == '|'); return $brs; }
function &_BrokenRules() { $brs = new Broken_Rules(); $gs =& GlobalSingleton::GetInstance(); $capMissingURL = $gs->GetText($locale, 'capMissingURL'); $capInvalidType = $gs->GetText($locale, 'capInvalidType'); $capSourceMustBeCap = $gs->GetText($locale, 'capSourceMustBeCaption'); $capAuthorRequired = $gs->GetText($locale, 'capAuthorRequired'); $capSchemaRequired = $gs->GetText($locale, 'capHTTP(s)SchemaRequired'); if ($this->Type() == 'r' && $this->Author() == "") { $brs->Add("AUTHOR_REQUIRED", $capAuthorRequired); } $brs->Assert("NO_URL", $capMissingURL, strlen($this->URL()) == 0); $brs->Assert("INVALID_TYPE", $capInvalidType, !in_array($this->Type(), $this->_validTypes)); $brs->Assert("SOURCE_NOT_CAP", $capSourceMustBeCap, strpos($this->Source(), 'cap') !== 0); $brs->Assert("HTTP_SCHEMA_REQ", $capSchemaRequired, substr(strtolower($this->Schema()), 0, 4) != "http"); return $brs; }
function BrokenRules() { /* TODO:MISSING Rule messages shouldn't be in English */ $brs = new Broken_Rules(); if (!$this->IsDirty()) { return $brs; } $children =& $this->Children(); foreach ($children as $child) { $bos =& $child['bos']; $br = $bos->BrokenRules(); $brs->Append(&$br); } foreach ($this->Method2Fields() as $method => $fieldName) { if ($fieldName != 'id') { $field = $this->_DBFields[$fieldName]; $val = $this->{$method}(); $type = $field['type']; $unsigned = $field['unsigned']; $length = $field['length']; $notnull = $field['notnull']; $isNumber = $type == 'integer' || $type == 'decimal' || $type == 'float'; $className = get_class($this); $stdErrMsg = "Inevitable DB Validation error prevented at {$className} -> {$method}"; if (is_null($val)) { if ($notnull) { $brs->Add('NULL', "{$stdErrMsg}; Value can't be null ({$val})"); } } else { switch ($type) { case 'text': if (strlen($val) > $length) { $brs->Add('WRONG_LENGTH', "{$stdErrMsg}; Expected length: {$length}; Actual length: " . strlen($val)); } break; case 'boolean': $brs->Assert('NOT_BOOLEAN', "{$stdErrMsg}; Expected type: boolean; Actual value: '{$val}'", !is_bool($val) && $val != 0 && $val != 1); break; /* These numeric types could be more finely tuned. The types are db dependent so it's difficult to determine exactly how to validate each one so we will just use is_numeric for now*/ /* These numeric types could be more finely tuned. The types are db dependent so it's difficult to determine exactly how to validate each one so we will just use is_numeric for now*/ case 'integer': case 'decimal': case 'float': $brs->Assert('NOT_NUMERIC', "{$stdErrMsg}; Expected type: numeric; Actual value: '{$val}'", !is_numeric($val)); if ($unsigned && $val < 0) { $brs->Add('NEGATIVE', "{$stdErrMsg}; Expected unsigned value; Actual value '{$val}'"); } break; case 'timestamp': $numericVal = strtotime($val); if ($numericVal === false || $numericVal == -1) { $brs->Add('NOT_DATE', "{$stdErrMsg}; Expected type: timestamp; Actual value: '{$val}'"); } break; case 'time': /* This is contrained to military time. Should be more forgiving */ $arr = explode(':', $val); if (!(count($arr) == 3 && is_numeric($arr[0]) && is_numeric($arr[1]) && is_numeric($arr[2]) && $arr[0] >= 0 && $arr[0] <= 23 && $arr[1] >= 0 && $arr[1] <= 59 && $arr[2] >= 0 && $arr[2] <= 59)) { /* Err msg should include format tips */ $brs->Add('NOT_TIME', "{$stdErrMsg}; Expected type: time; Actual value: '{$val}'"); } break; case 'date': $numericVal = strtotime($val); if ($numericVal === false || $numericVal == -1) { $brs->Add('NOT_DATE', "{$stdErrMsg}; Expected type: date; Actual value: '{$val}'"); } case 'clob': break; case 'blob': break; } } } } if (method_exists($this, '_BrokenRules')) { $privBrs =& $this->_BrokenRules(); $brs->Append($privBrs); } return $brs; }