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::uses('FieldDefinition', 'ExtendedScaffold.Lib');
  4: App::uses('FieldRowDefinition', 'ExtendedScaffold.Lib');
  5: App::uses('FieldSetDefinition', 'ExtendedScaffold.Lib');
  6: 
  7: class ExtendedFieldsParser {
  8:     const EXTENDED_KEY = '_extended';
  9: 
 10:     public static function &getInstance() {
 11:         static $instance = array();
 12: 
 13:         if (!$instance) {
 14:             $instance[0] = new ExtendedFieldsParser();
 15:         }
 16:         return $instance[0];
 17:     }
 18: 
 19:     public static function isExtendedFieldsDefinition($fields) {
 20:         return isset($fields[self::EXTENDED_KEY]);
 21:     }
 22: 
 23:     /**
 24:      * 
 25:      * @param array $fields
 26:      * @return FieldSetDefinition[]
 27:      * @throws Exception
 28:      */
 29:     public static function extractExtendedFields($fields) {
 30:         $_this = & self::getInstance();
 31:         if ($_this->isExtendedFieldsDefinition($fields)) {
 32:             return $fields[self::EXTENDED_KEY];
 33:         } else {
 34:             throw new Exception("Parâmetro \$fields não é uma definição extendida.");
 35:         }
 36:     }
 37: 
 38:     public static function parseFieldsets($fieldsData, $defaultModel = null) {
 39:         $_this = & self::getInstance();
 40: 
 41:         if ($_this->isExtendedFieldsDefinition($fieldsData)) {
 42:             $fieldsData = $_this->extractExtendedFields($fieldsData);
 43:             $fieldsets = array();
 44:             foreach ($fieldsData as $dataKey => $dataValue) {
 45:                 $fieldsets[] = $_this->_parseFieldsetData($dataKey, $dataValue, $defaultModel);
 46:             }
 47:             return $fieldsets;
 48:         } else {
 49:             return array(
 50:                 $_this->_parseFieldsetData(0, array(
 51:                     'lines' => $fieldsData
 52:                         ), $defaultModel)
 53:             );
 54:         }
 55:     }
 56: 
 57:     public function fieldInDefinition($fieldsData, $field, $defaultModel = null) {
 58:         $_this = & self::getInstance();
 59:         $fieldSets = $this->parseFieldsets($fieldsData);      
 60:         
 61:         foreach ($fieldSets as $fieldSet) {
 62:             foreach ($fieldSet['lines'] as $line) {
 63:                 foreach ($line as $lineField) {                    
 64:                     if (AppBasics::fieldFullName($lineField['name'], $defaultModel) == AppBasics::fieldFullName($field, $defaultModel)) {
 65:                         return true;
 66:                     }
 67:                 }
 68:             }
 69:         }
 70: 
 71:         return false;
 72:     }
 73: 
 74:     private function _parseFieldsetData($key, $value, $defaultModel = null) {
 75:         $_this = & self::getInstance();
 76:         $listAssociation = $legend = $accessObject = $accessObjectType = false;
 77:         if (is_array($value)) {
 78:             foreach(array('legend','listAssociation', 'accessObject','accessObjectType') as $field) {
 79:                 if (!empty($value[$field])) {
 80:                     ${$field}= $value[$field];
 81:                     unset($value[$field]);
 82:                 }
 83:             }
 84:             if (!empty($value['lines'])) {
 85:                 $lines = $_this->_parseLinesData($value['lines'], $defaultModel);
 86:                 unset($value['lines']);
 87:             } else {
 88:                 $lines = $_this->_parseLinesData($value, $defaultModel);
 89:             }
 90:         } else {
 91:             $lines = array($_this->_parseLineData($value, $defaultModel));
 92:         }
 93: 
 94:         return new FieldSetDefinition($lines, compact('legend', 'listAssociation', 'accessObject', 'accessObjectType'));
 95:     }
 96: 
 97:     private function _parseLinesData($value, $defaultModel = null) {
 98:         $_this = & self::getInstance();
 99:         $linesData = array();
100:         foreach ($value as $subKey => $subValue) {
101:             $linesData[] = $_this->_parseLineData($subKey, $subValue, $defaultModel);
102:         }
103:         return $linesData;
104:     }
105: 
106:     private function _parseLineData($key, $value, $defaultModel = null) {
107:         if (($field = $this->_parseFieldData($key, $value, $defaultModel))) {
108:             $fields = array($field);
109:         } else if (is_array($value)) {
110:             $fields = array();
111:             foreach ($value as $subKey => $subValue) {
112:                 $field = $this->_parseFieldData($subKey, $subValue, $defaultModel);
113:                 if ($field === false) {
114:                     throw new Exception("Error on parse field: " . print_r(compact('key', 'value'), true));
115:                 }
116:                 $fields[] = $field;
117:             }
118:         } else {
119:             throw new Exception("Error on parse line: " . print_r(compact('key', 'value'), true));
120:         }
121:         return new FieldRowDefinition($fields);
122:     }
123: 
124:     /**
125:      * 
126:      * @param type $key
127:      * @param type $value
128:      * @param type $defaultModel
129:      * @return FieldDefinition
130:      */
131:     private function _parseFieldData($key, $value, $defaultModel = null) {
132:         if ((is_int($key) && preg_match('/^\d+$/', $key) && is_string($value))) {
133:             $name = $value;
134:             $options = array();
135:         } else if (is_string($key) && preg_match('/^[^\d]/', $key) && is_array($value)) {
136:             $name = $key;
137:             $options = $value;
138:         } else {
139:             return false;
140:         }
141:         $nameParts = explode('.', $name);
142:         if (count($nameParts) == 1 && $defaultModel) {
143:             $name = "$defaultModel.{$nameParts[0]}";
144:         }
145:         return new FieldDefinition($name, $options);
146:     }
147: 
148: }
149: 
150: ?>
151: 
API documentation generated by ApiGen 2.8.0