Overview

Namespaces

  • Cron
  • None

Classes

  • _HtmlGrid_TableOut
  • _TransactionModel_RawSaveOperation
  • AccessControlComponent
  • AccessControlHelper
  • ActionListHelper
  • ActiveDirectoryUtils
  • AddCurrentPidToSchedulingShellCallLogs
  • AnonymousFunctionOperation
  • ArrayUtil
  • AssociationIntegrityBehavior
  • AtomicOperation
  • AuthenticationComponent
  • AuthenticationController
  • AuthenticationUser
  • AutocompleteDatasourceComponent
  • BaseModelComponent
  • Basics
  • CakeLayersHelper
  • CheckAndRunShell
  • ClassSearcher
  • CommandLineUtil
  • CommonValidationBehavior
  • ConfigurableShellCallsSchedulingTask
  • ConfigurationKey
  • ConfigurationKeys
  • ConfigurationKeysController
  • Context
  • ContextComponent
  • ContextHelper
  • Contexts
  • ControllerInspector
  • ControllerMenuHelper
  • CreateJournalingTables
  • CreateTableConfigurationKeys
  • CreateTableSchedulingConfigurableShellCalls
  • CreateTableSchedulingShellCallLogs
  • CreateTableSettedConfigurationKeys
  • CreateTableUserResetPasswordRequests
  • CreateTableUsers
  • CronSchedulingInstaller
  • CronValidationBehavior
  • CssBox
  • CssController
  • CssProperties
  • CssShell
  • CsvUtil
  • CustomDataModel
  • DatasourceDumperManager
  • DateTimeInput
  • DependencyShell
  • DetailHelper
  • DumperShell
  • ExtendedFieldsAccessControl
  • ExtendedFieldSet
  • ExtendedFieldSetHelper
  • ExtendedFieldsParser
  • ExtendedFormHelper
  • ExtendedHasManyAppModel
  • ExtendedOperationsBehavior
  • FieldDefinition
  • FieldRowDefinition
  • FieldSetDefinition
  • FieldSetLayoutHelper
  • FileOperations
  • FileOperations_Rename
  • FileOperations_SymLink
  • FileOperations_Touch
  • FileOperations_Unlink
  • FileSystem
  • FixConfigurationKeysPrimaryKey
  • FixSettedConfigurationKeysPrimaryKey
  • HasManyUtilsBehavior
  • HtmlDocument
  • HtmlGrid
  • HtmlGrid_Cell
  • HttpClient
  • HttpResponse
  • ImapClient
  • ImapMailBox
  • ImapParserShell
  • IncludePath
  • InputMasked
  • InputSearchable
  • InputsOnSubmit
  • InstallShell
  • JenkinsBuildShell
  • Journal
  • JournalDetail
  • JournalizedBehavior
  • JsonResponseComponent
  • LayoutsHelper
  • Ldap
  • LdapUtils
  • ListFieldSet
  • ListFieldSetHelper
  • ListsHelper
  • MailParser
  • Make
  • MenuHelper
  • MigrationAllPluginsShell
  • ModelOperations
  • ModelOperations_Delete
  • ModelOperations_Save
  • ModelTraverser
  • MysqlDumper
  • OpenLdapUtils
  • PaginatorUtilComponent
  • PaginatorUtilComponentFilter
  • PaginatorUtilHelper
  • Plugin
  • PluginManager
  • Reflections
  • RenameEnabledToActiveFromUsersTable
  • RunShellCallShell
  • ScaffoldUtilComponent
  • ScaffoldUtilHelper
  • Scheduling
  • SchedulingConfigurableShellCall
  • SchedulingConfigurableShellCallsController
  • SchedulingShellCallLog
  • SchedulingShellCallLogsController
  • SettedConfigurationKey
  • StuffreposPluginsRename
  • TimeZoneBehavior
  • TransactionModel
  • TransactionOperation
  • Translator
  • TranslatorShell
  • User
  • UserAuthenticationComponent
  • UserChangePassword
  • UserResetPassword
  • UserResetPasswordRequest
  • UserResetPasswordRequestSubmission
  • UsersController
  • ViewUtilHelper

Interfaces

  • AccessControlFilter
  • CommitableOperation
  • DatasourceDumper
  • MakeListener
  • SchedulingInstaller
  • TasksObject
  • UndoableOperation

Exceptions

  • LdapObjectNotWritableException
  • ModelTraverserException
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: App::import('Lib', 'Base.Basics');
  4: 
  5: class CommonValidationBehavior extends ModelBehavior {
  6: 
  7:     const EMPTY_VALUE = '@EMPTY_VALUE@';
  8: 
  9:     private $modelSettingsDefault = array(
 10:         'forceValidateEmpty' => array(),
 11:     );
 12: 
 13:     public function setup(\Model $model, $config = array()) {
 14:         parent::setup($model, $config);
 15:         $this->settings[$model->name] = array_merge($this->modelSettingsDefault, $config);
 16:     }
 17: 
 18:     public function beforeValidate(\Model $model, $options = array()) {
 19:         if (!parent::beforeValidate($model, $options)) {
 20:             return false;
 21:         }
 22:         foreach ($this->settings[$model->name]['forceValidateEmpty'] as $field) {
 23:             if (empty($model->data[$model->alias][$field]) || trim($model->data[$model->alias][$field]) == '') {
 24:                 $model->data[$model->alias][$field] = self::EMPTY_VALUE;
 25:             }
 26:         }
 27:         return true;
 28:     }
 29: 
 30:     public function beforeSave(\Model $model, $options = array()) {
 31:         if (!parent::beforeSave($model, $options)) {
 32:             return false;
 33:         }
 34:         foreach ($this->settings[$model->name]['forceValidateEmpty'] as $field) {
 35:             if ($model->data[$model->alias][$field] == self::EMPTY_VALUE) {
 36:                 $model->data[$model->alias][$field] = '';
 37:             }
 38:         }
 39:         return true;
 40:     }
 41: 
 42:     public static function isUniqueInContext(Model $model, $check, $contextFields = array()) {
 43:         $contextFields = ArrayUtil::arraylize($contextFields);                
 44: 
 45:         foreach ($check as $field => $value) {
 46:             $conditions = array(
 47:                 "{$model->alias}.$field" => $value,
 48:             );
 49: 
 50:             foreach ($contextFields as $contextField) {
 51:                 $contextFieldValue = self::currentFieldValue(
 52:                                 $model
 53:                                 , $contextField
 54:                 );
 55: 
 56:                 if ($contextFieldValue === null) {
 57:                     return false;
 58:                 }                                
 59: 
 60:                 $conditions[Basics::fieldFullName($contextField, $model->alias)] = $contextFieldValue;
 61:             }
 62: 
 63:             $result = $model->find(
 64:                     'first', compact('conditions')
 65:             );                        
 66: 
 67:             if (!empty($result)) {
 68:                 if (empty($model->data[$model->alias][$model->primaryKey])) {
 69:                     return false;
 70:                 } else {
 71:                     return $model->data[$model->alias][$model->primaryKey] == $result[$model->alias][$model->primaryKey];
 72:                 }
 73:             }
 74:         }
 75: 
 76:         return true;
 77:     }
 78: 
 79:     public static function foreignKey(Model $model, $check) {
 80:         foreach ($check as $field => $value) {
 81:             if (!$value) {
 82:                 return false;
 83:             }
 84:         }
 85:         return true;
 86:     }
 87: 
 88:     private static function currentFieldValue(Model $model, $contextField) {
 89:         $dataField = Basics::fieldValue($model->data, $contextField, $model->alias);
 90:         if ($dataField !== null) {
 91:             return $dataField;
 92:         }
 93: 
 94:         if (($primaryKeyValue = Basics::fieldValue($model->data, $model->primaryKey, $model->alias))) {
 95:             $instance = $model->find(
 96:                     'first'
 97:                     , array(
 98:                 'conditions' => array(
 99:                     "{$model->alias}.{$model->primaryKey}" => $primaryKeyValue
100:                 )
101:                     )
102:             );
103: 
104:             if (($fieldValue = Basics::fieldValue($instance, $field, $model->alias))) {
105:                 return $fieldValue;
106:             }
107:         }
108: 
109:         return null;
110:     }
111: 
112: }
113: 
114: ?>
115: 
API documentation generated by ApiGen 2.8.0