06.27
php
saved
jmikola
Note
jmikola did not leave a note
jmikola did not leave a note
- <?php
- /**
- * Common validation error messages.
- */
- /**
- * Application model for Cake.
- *
- * This is a placeholder class.
- * Create the same file in app/app_model.php
- * Add your application-wide methods to the class, your models will inherit them.
- *
- * @package cake
- * @subpackage cake.cake
- */
- class AppModel extends Model {
- /**
- * Validation replacement for Model::isUnique. Checks uniqueness of one or
- * multiple fields at once. If the $ignore_on parameter specifies a field
- * name, a potential conflict will be ignored if this model shares a value
- * with that field. This is most useful during an update, where we only
- * need to validate against other records with different id's.
- *
- * @param mixed $data Field value (ignored)
- * @param mixed $fieldNames Field name if a string, or an array of names (must not include Model name in dotted notation)
- * @param boolean $or If false, all fields must match for isUnique to return false
- * @param string $ignore_on_same Field name to ignore conflicts with
- * @return boolean True if field value is unique; otherwise, false
- */
- function checkUnique($data, $fieldNames, $or = true, $ignore_on_same = 'id') {
- // No need to perform any joins
- $this->recursive = -1;
- // Pack fieldNames into an array, if a single field was specified
- }
- // If fieldNames isn't an array by this point, the parameter was invalid
- return false;
- }
- foreach ($fieldNames as $fieldName) {
- // Ensure all fields to be checked exist in the Model and $data array
- return false;
- }
- $fieldValue = $this->data[$this->alias][$fieldName];
- // Prefex $fieldName with model name for the full field name
- $fieldName = $this->alias . '.' . $fieldName;
- // Construct $fields parameter for Model::isUnique
- $fields[$fieldName] = $fieldValue;
- }
- // Groups field conditions in an OR clause if necessary
- // Note: AND parent is necessary since cake does not properly surround
- // the OR constraints with parentheses
- if ($or) {
- }
- // Append $ignore_on_same as an AND comparison if possible
- // Construct full field name and append "!=" SQL operator
- $key = $this->alias . '.' . $ignore_on_same . ' <>';
- $val = $this->data[$this->alias][$ignore_on_same];
- // Use array_merge to prepend this clause, which is necessary in
- // case all previous fields were grouped under an OR comparison
- }
- }
- }
- ?>
Parsed in 0.118 seconds, using GeSHi 1.0.7.14