Skip to content

Commit

Permalink
[#13697] - Removed collection references
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Sep 7, 2019
1 parent e0e0d72 commit 737d30e
Showing 1 changed file with 79 additions and 79 deletions.
158 changes: 79 additions & 79 deletions phalcon/Validation/Validator/Uniqueness.zep
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
namespace Phalcon\Validation\Validator;

use Phalcon\Messages\Message;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Validation;
use Phalcon\Validation\AbstractCombinedFieldsValidator;
use Phalcon\Validation\Exception;
use Phalcon\Mvc\ModelInterface;
use Phalcon\Mvc\CollectionInterface;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Collection;
//use Phalcon\Mvc\CollectionInterface;
//use Phalcon\Mvc\Collection;

/**
* Check that a field is unique in the related table
Expand Down Expand Up @@ -170,13 +170,13 @@ class Uniqueness extends AbstractCombinedFieldsValidator
}
}

let isModel = record instanceof ModelInterface,
isDocument = record instanceof CollectionInterface;
let isModel = record instanceof ModelInterface;
// let isDocument = record instanceof CollectionInterface;

if isModel {
let params = this->isUniquenessModel(record, field, values);
} elseif isDocument {
let params = this->isUniquenessCollection(record, field, values);
// } elseif isDocument {
// let params = this->isUniquenessCollection(record, field, values);
} else {
throw new Exception(
"The uniqueness validator works only with Phalcon\\Mvc\\Model or Phalcon\\Mvc\\Collection"
Expand All @@ -188,77 +188,77 @@ class Uniqueness extends AbstractCombinedFieldsValidator
return {className}::count(params) == 0;
}

/**
* Uniqueness method used for collection
*/
protected function isUniquenessCollection(var record, array field, array values)
{
var exceptConditions, fieldExcept, notInValues, value, singleField,
params, except, singleExcept;

let exceptConditions = [];
let params = [
"conditions" : []
];

for singleField in field {
let fieldExcept = null;
let notInValues = [];
let value = values[singleField];

let except = this->getOption("except");

let params["conditions"][singleField] = value;

if except {
if typeof except == "array" && count(field) > 1 {
if isset except[singleField] {
let fieldExcept = except[singleField];
}
}

if fieldExcept != null {
if typeof fieldExcept == "array" {
for singleExcept in fieldExcept {
let notInValues[] = singleExcept;
}

let exceptConditions[singleField] = [
"$nin": notInValues
];
} else {
let exceptConditions[singleField] = [
"$ne": fieldExcept
];
}
} elseif typeof except == "array" && count(field) == 1 {
for singleExcept in except {
let notInValues[] = singleExcept;
}

let params["conditions"][singleField] = [
"$nin": notInValues
];
} elseif count(field) == 1 {
let params["conditions"][singleField] = [
"$ne": except
];
}
}
}

if record->getDirtyState() == Collection::DIRTY_STATE_PERSISTENT {
let params["conditions"]["_id"] = [
"$ne": record->getId()
];
}

if !empty exceptConditions {
let params["conditions"]["$or"] = [exceptConditions];
}

return params;
}
// /**
// * Uniqueness method used for collection
// */
// protected function isUniquenessCollection(var record, array field, array values)
// {
// var exceptConditions, fieldExcept, notInValues, value, singleField,
// params, except, singleExcept;
//
// let exceptConditions = [];
// let params = [
// "conditions" : []
// ];
//
// for singleField in field {
// let fieldExcept = null;
// let notInValues = [];
// let value = values[singleField];
//
// let except = this->getOption("except");
//
// let params["conditions"][singleField] = value;
//
// if except {
// if typeof except == "array" && count(field) > 1 {
// if isset except[singleField] {
// let fieldExcept = except[singleField];
// }
// }
//
// if fieldExcept != null {
// if typeof fieldExcept == "array" {
// for singleExcept in fieldExcept {
// let notInValues[] = singleExcept;
// }
//
// let exceptConditions[singleField] = [
// "$nin": notInValues
// ];
// } else {
// let exceptConditions[singleField] = [
// "$ne": fieldExcept
// ];
// }
// } elseif typeof except == "array" && count(field) == 1 {
// for singleExcept in except {
// let notInValues[] = singleExcept;
// }
//
// let params["conditions"][singleField] = [
// "$nin": notInValues
// ];
// } elseif count(field) == 1 {
// let params["conditions"][singleField] = [
// "$ne": except
// ];
// }
// }
// }
//
// if record->getDirtyState() == Collection::DIRTY_STATE_PERSISTENT {
// let params["conditions"]["_id"] = [
// "$ne": record->getId()
// ];
// }
//
// if !empty exceptConditions {
// let params["conditions"]["$or"] = [exceptConditions];
// }
//
// return params;
// }

/**
* Uniqueness method used for model
Expand Down

0 comments on commit 737d30e

Please sign in to comment.