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.ArrayUtil');
  4: 
  5: class Basics {
  6: 
  7:     /**
  8:      * Converte uma URL para o formato do parĂ¢metro $url
  9:      * em Router::url().
 10:      * @param string|array $url
 11:      * @return array
 12:      */
 13:     public function parseUrl($url) {
 14:         if (!is_array($url)) {
 15:             $url = Router::parse($url);
 16:         }
 17:         foreach (array('named', 'pass') as $urlKey) {
 18:             if (!empty($url[$urlKey])) {
 19:                 foreach ($url[$urlKey] as $key => $value) {
 20:                     $url[$key] = $value;
 21:                 }
 22:             }
 23:             unset($url[$urlKey]);
 24:         }
 25:         return $url;
 26:     }
 27: 
 28:     /**
 29:      *
 30:      * @param array $data
 31:      * @param string $field
 32:      * @param string $defaultModel 
 33:      * @return mixed
 34:      */
 35:     public static function fieldValue($data, $field, $defaultModel) {
 36:         return ArrayUtil::arrayIndex($data, self::fieldPath($field, $defaultModel));
 37:     }
 38: 
 39:     /**
 40:      *
 41:      * @param string $field
 42:      * @param string $defaultModel
 43:      * @return array 
 44:      */
 45:     public static function fieldPath($field, $defaultModel) {
 46:         $fieldPath = explode('.', $field);
 47: 
 48:         if (count($fieldPath) == 1 && $defaultModel) {
 49:             $fieldPath = array_merge(array($defaultModel), $fieldPath);
 50:         }
 51:         return $fieldPath;
 52:     }
 53: 
 54:     /**
 55:      *
 56:      * @param string $field
 57:      * @param string $defaultModel
 58:      * @return string
 59:      */
 60:     public static function fieldFullName($field, $defaultModel) {
 61:         return implode('.', self::fieldPath($field, $defaultModel));
 62:     }
 63: 
 64:     /**
 65:      * Converte um nome de campo (Identificadores separados por ponto) para um 
 66:      * array
 67:      * @param string $fieldName 
 68:      */
 69:     public static function fieldNameToArray($fieldName) {
 70:         return explode('.', $fieldName);
 71:     }
 72: 
 73:     public static function lcd($n, $m, $maxvarianzpercent = 0) {
 74:         // set $maxvarianzpercent=5 to get a small, but approx. result
 75:         /* a better lcd function with varianz:
 76:           for example use
 77:           lcd(141,180,5) to get the approx. lcd '7/9' which is in fact 140/180
 78:          */
 79:         // ATTENTION!!! can be really slow if $m is >1000
 80: 
 81:         $d = $n / $m;
 82:         $f = 1;
 83:         while ($d * $f != intval($d * $f)) {
 84:             $f++;
 85:         }
 86:         $r = ($d * $f) . '/' . $f;
 87:         if (($d * $f) <= 10 or $f <= 10)
 88:             return $r;
 89:         else if ($maxvarianzpercent > 0) {
 90:             $f = 1;
 91:             while ($d * $f != intval($d * $f) and ($d * $f) - intval($d * $f) > $maxvarianzpercent / 100) {
 92:                 $f++;
 93:             }
 94:             return intval($d * $f) . '/' . $f;
 95:         } else
 96:             return $r;
 97:     }
 98: 
 99:     public static function multibyteTrim($string) {
100:         $string = preg_replace("/(^\s+)|(\s+$)/us", "", $string);
101: 
102:         return $string;
103:     }
104: 
105:     /**
106:      * 
107:      * @param mixed $model A Model or a model name (string)
108:      * @param array $data
109:      * @return array
110:      * @throws Exception
111:      */
112:     public static function saveModelOrThrowException($model, $data) {
113:         $model = self::_getModel($model);
114:         
115:         if (empty($data[$model->alias][$model->primaryKey])) {
116:             $model->create();
117:         }
118: 
119:         if (!$model->save($data)) {
120:             $validationErrors = $model->validationErrors;
121:             $alias = $model->alias;
122:             throw new Exception("Failed to save {$model->name}: " . print_r(compact('data', 'validationErrors', 'alias'), true));
123:         } else {
124:             return $model->read();
125:         }
126:     }
127: 
128:     public static function deleteModelOrThrowException($model, $data) {
129:         $model = self::_getModel($model);
130:         if (!$model->delete($data[$model->alias][$model->primaryKey])) {
131:             $alias = $model->alias;
132:             throw new Exception("Failed to delete {$model->name}: " . print_r(compact('data', 'alias'), true));
133:         }
134:     }
135: 
136:     /**
137:      * 
138:      * @param mixed $model A Model or a model name (string)
139:      * @return \Model
140:      * @throws Exception
141:      */
142:     private static function _getModel($model) {
143:         if ($model instanceof Model) {
144:             return $model;
145:         } else if (is_string($model)) {
146:             $modelName = $model;
147:             $model = ClassRegistry::init($modelName);
148:             if ($model instanceof Model) {
149:                 return $model;
150:             } else {
151:                 throw new Exception("\"$modelName\" is not a Model's name");
152:             }
153:         } else {
154:             throw new Exception("Parameter \$model is not a Model neither a string name");
155:         }
156:     }
157: 
158: }
159: 
160: ?>
161: 
API documentation generated by ApiGen 2.8.0