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: /*
  4:  * Copyright 2010 Eduardo H. Bogoni <eduardobogoni@gmail.com>
  5:  *
  6:  * This file is part of CakePHP Bog Util.
  7:  *
  8:  * CakePHP Bog Util is free software: you can redistribute it and/or modify
  9:  * it under the terms of the GNU General Public License as published by the Free
 10:  * Software Foundation, either version 3 of the License, or (at your option) any
 11:  * later version.
 12:  *
 13:  * CakePHP Bog Util is distributed in the hope that it will be useful, but
 14:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 15:  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 16:  * details.
 17:  *
 18:  * You should have received a copy of the GNU General Public License along with
 19:  * CakePHP Bog Util. If not, see http://www.gnu.org/licenses/.
 20:  */
 21: 
 22: App::uses('Component', 'Controller');
 23: App::uses('ExtendedFieldsParser', 'ExtendedScaffold.Lib');
 24: App::uses('ExtendedFieldsAccessControl', 'ExtendedScaffold.Lib');
 25: App::uses('Basics', 'Base.Lib');
 26: 
 27: /**
 28:  * 
 29:  */
 30: class ScaffoldUtilComponent extends Component {
 31: 
 32:     const OPTION_NAME_SEPARATOR = ',';
 33:     public $components = array('Session');
 34:     public $currentAction = null;
 35:     public $defaultOptions;
 36:     private $referer;
 37:         
 38:     public function startup(Controller $controller) {
 39:         parent::startup($controller);
 40:         $this->controller = $controller;
 41:         if ($this->controller->modelClass) {
 42:             $this->defaultOptions = array(
 43:                 'indexUnsetFields,viewUnsetFields' => array(
 44:                     $this->controller->{$this->controller->modelClass}->primaryKey
 45:                 )
 46:             );
 47:         } else {
 48:             $this->defaultOptions = array();
 49:         }
 50:         $this->_removeDeniedData($controller);
 51:         $this->_fetchRefererFromRequest($controller);
 52:     }
 53: 
 54:     public function beforeRender(Controller $controller) {
 55:         parent::beforeRender($controller);
 56:         $this->currentAction = $controller->params['action'];
 57:         $this->_interceptScaffoldFields($controller);
 58:         $this->_setRefererOnData($controller);
 59:     }
 60: 
 61:     public function referer() {
 62:         return $this->referer;
 63:     }
 64: 
 65:     private function _interceptScaffoldFields(\Controller $controller) {
 66:         if (isset($controller->viewVars['scaffoldFields'])) {
 67:             $controller->set('scaffoldFields', $this->_buildScaffoldFields($controller));
 68:         }
 69:     }
 70: 
 71:     private function _buildScaffoldFields(\Controller $controller) {
 72:         if ($this->_getActionOption('setFields')) {
 73:             $scaffoldFields = $this->_getActionOption('setFields');
 74:         } else if (array_key_exists ('scaffoldFields', $controller->viewVars)){
 75:             $scaffoldFields = $controller->viewVars['scaffoldFields'];
 76:         } else {
 77:             return array();
 78:         }
 79: 
 80:         if ($this->_getActionOption('appendFields')) {
 81:             $scaffoldFields = array_merge(
 82:                     $scaffoldFields, $this->_getActionOption('appendFields')
 83:             );
 84:         }
 85: 
 86:         if (empty($scaffoldFields['_extended'])) {
 87:             if ($this->_getActionOption('unsetFields')) {
 88:                 $tempFields = array();
 89:                 foreach ($scaffoldFields as $key => $value) {
 90:                     $field = is_array($value) ? $key : $value;
 91:                     if (!in_array($field, $this->_getActionOption('unsetFields'))) {
 92:                         $tempFields[$key] = $value;
 93:                     }
 94:                 }
 95:                 $scaffoldFields = $tempFields;
 96:             }
 97:         }
 98:         return $scaffoldFields;
 99:     }
100: 
101:     private function _removeDeniedData(\Controller $controller) {
102:         foreach ($controller->request->data as $modelAlias => $fields) {
103:             foreach (array_keys($fields) as $field) {
104: 
105:                 if ($this->_shouldRemoveData($controller, $modelAlias, $field)) {
106:                     unset($controller->request->data[$modelAlias][$field]);
107:                 }
108:             }
109:         }
110:     }
111: 
112:     private function _shouldRemoveData(\Controller $controller, $modelAlias, $field) {
113:         $scaffolfFields = $this->_buildScaffoldFields($controller);
114:         $definition = ExtendedFieldsParser::parseFieldsets($scaffolfFields);        
115:         foreach ($definition as $fieldSet) {
116:             foreach ($fieldSet->getLines() as $line) {
117:                 foreach ($line->getFields() as $extendedFieldsParserField) {
118:                     if ($this->_fieldNameEquals($controller, $extendedFieldsParserField, "$modelAlias.$field")) {
119:                         return !ExtendedFieldsAccessControl::sessionUserHasFieldAccess($extendedFieldsParserField, false)
120:                                 || !ExtendedFieldsAccessControl::sessionUserHasFieldSetAccess($fieldSet, false);
121:                     }
122:                 }
123:             }
124:         }
125:         return false;
126:     }
127: 
128:     private function _fieldNameEquals(\Controller $controller, \FieldDefinition $extendedFieldsParserField, $name) {
129:         $defaultModel = empty($controller->uses[0]) ?
130:                 null :
131:                 ClassRegistry::init($controller->uses[0])->alias;
132:         return Basics::fieldFullName($extendedFieldsParserField->getName(), $defaultModel) ==
133:         Basics::fieldFullName($name, $defaultModel);
134:     }
135: 
136:     private function _fetchRefererFromRequest(\Controller $controller) {
137:         if (empty($controller->request->data['_ScaffoldUtil']['referer'])) {
138:             $this->referer = $controller->referer();
139:         }
140:         else {
141:             $this->referer = $controller->request->data['_ScaffoldUtil']['referer'];
142:         }        
143:     }
144:     
145:     private function _setRefererOnData(\Controller $controller) {
146:         $controller->request->data['_ScaffoldUtil']['referer'] = $this->referer;
147:     }
148: 
149:     public function addJavascriptLink($file) {
150:         $this->controller->params[__CLASS__]['javascriptLinks'][] = $file;
151:     }
152:     
153:     public function render($action, $scaffoldFields = array()) {                
154:         App::import('Lib', 'Scaffold');
155:         
156:         $this->controller->viewClass = 'Scaffold';
157:         $this->controller->set('pluralVar',Inflector::variable($this->controller->name));
158:         $this->controller->set('singularVar', Inflector::variable($this->controller->modelClass));
159:         $this->controller->set('singularHumanName', Inflector::humanize(Inflector::underscore($this->controller->modelClass)));
160:         $this->controller->set('scaffoldFields', $scaffoldFields);
161:         $this->controller->render($action);
162:     }
163: 
164:     private function _getActionOption($name) {
165:         $action = ($this->currentAction ? $this->currentAction : $this->controller->params['action']);
166:         $optionName = Inflector::camelize($action . '_' . Inflector::underscore($name));
167:         $optionName = strtolower(substr($optionName, 0, 1)) . substr($optionName, 1, strlen($optionName) - 1);
168:         return $this->_findOption($optionName);                
169:     }
170:     
171:     private function _findOption($optionName) {
172:         if (is_array($this->settings)) {
173:             foreach ($this->settings as $key => $value) {
174:                 foreach (explode(self::OPTION_NAME_SEPARATOR, $key) as $keyOption) {
175:                     if (trim($keyOption) == trim($optionName)) {
176:                         return $value;
177:                     }
178:                 }
179:             }
180:         }
181: 
182:         foreach($this->defaultOptions as $key => $value) {
183:             foreach(explode(self::OPTION_NAME_SEPARATOR,$key) as $keyOption) {
184:                 if (trim($keyOption) == trim($optionName)) {
185:                     return $value;
186:                 }
187:             }
188:         }
189:         
190:         return false;
191:     }
192: 
193: }
194: 
API documentation generated by ApiGen 2.8.0