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: class AutocompleteDatasourceComponent extends Component {
 4:     
 5:     public function startup(Controller $controller) {
 6:         parent::startup($controller);
 7:         if (!empty($controller->params['url']['_autocompleteDatasource'])) {
 8:             $modelName = empty($controller->params['url']['modelName']) ? $controller->modelClass : $controller->params['url']['modelName'];
 9:             $Model = ClassRegistry::init($modelName);
10:             $term = empty($controller->params['url']['term']) ? '' : $controller->params['url']['term'];
11:             $id = empty($controller->params['url']['id']) ? '' : $controller->params['url']['id'];
12:             $queryField = empty($controller->params['url']['queryField']) ? $Model->displayField : $controller->params['url']['queryField'];
13:             $displayField = empty($controller->params['url']['displayField']) ? $queryField : $controller->params['url']['displayField'];
14:             $termInAnyPlace = empty($controller->params['url']['termInAnyPlace']) ||
15:                     strtolower(trim($controller->params['url']['termInAnyPlace'])) == 'false' ?
16:                     false :
17:                     $controller->params['url']['termInAnyPlace'];
18: 
19:             $options = compact(
20:                     'term', 'queryField', 'displayField', 'termInAnyPlace', 'id'
21:             );
22: 
23:             if (empty($id)) {
24:                 $data = $this->_query($Model, $options);
25:             } else {
26:                 $data = $this->_queryById($Model, $options);
27:             }
28: 
29:             echo json_encode($data);
30:             exit;
31:         }        
32:     }
33: 
34:     private function _query(Model $Model, $options) {
35:         $rows = $Model->find(
36:                 'all', array(
37:             'conditions' => $this->_queryConditions($Model, $options),
38:             'order' => $this->_queryOrder($Model, $options),
39:             'limit' => 50,
40:                 )
41:         );
42: 
43:         $data = array();
44: 
45:         foreach ($rows as $row) {
46:             $data[] = $this->_packageRow($Model, $options, $row);
47:         }
48: 
49:         return $data;
50:     }
51: 
52:     private function _packageRow($Model, $options, $row) {
53:         return array(
54:             'id' => $row[$Model->alias][$Model->primaryKey],
55:             'value' => $row[$Model->alias][$options['displayField']],
56:             'label' => $row[$Model->alias][$options['displayField']],
57:         );
58:     }
59: 
60:     private function _queryConditions($Model, $options) {
61:         $conditions = array();
62: 
63:         if (empty($options['termInAnyPlace'])) {
64:             $conditions["lower({$Model->alias}.{$options['queryField']}) like lower(concat(?,'%'))"] = trim($options['term']);
65:         } else {
66:             $conditions["lower({$Model->alias}.{$options['queryField']}) like lower(concat('%',?,'%'))"] = trim($options['term']);
67:         }
68: 
69:         return $conditions;
70:     }
71: 
72:     private function _queryOrder($Model, $options) {
73:         return "{$Model->alias}.{$options['displayField']}";
74:     }
75: 
76:     private function _queryById($Model, $options) {
77:         $row = $Model->find(
78:                 'all', array(
79:             'conditions' => array(
80:                 "{$Model->alias}.{$Model->primaryKey}" => $options['id']
81:             )
82:                 )
83:         );
84: 
85:         return $this->_packageRow($Model, $options, $row);
86:     }
87: 
88: }
89: 
90: ?>
91: 
API documentation generated by ApiGen 2.8.0